Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

I want to use List<String> in JPQL syntaxis

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
Can I use List<CardIds> in JPQL syntaxsis? I can, please write.
Thanks

public int getCardsByIdsSorted(//List<String> cardIds,
String field, boolean ascending) {
int a = 0;
List<Card> cardList; //= new ArrayList<Card>();
List<String> cardIds = new ArrayList<String>();
cardIds.add("66b72972-ea0e-4b24-a692-f220da739298");
cardIds.add("35676406-0fd4-4fd2-9ca7-22c628978983");
cardIds.add("520602e3-bd47-486c-8824-b2ac7d4957ab");
try {
cardList = entityManager.createQuery("SELECT t FROM Card t WHERE t.id IN (:cardIds)").setParameter("cardIds", cardIds).getResultList();
a = cardList.size();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}

return a;
}
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try the following:



Next time...could you put your code inside "Code" tags?...
it would make it more readable ;)

Regards
Dave
 
Rufat Babakishiyev
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for attention
cardList = entityManager.createQuery("SELECT t FROM Card t WHERE t.id IN (:cardIds)").setParameterList("cardIds", cardIds).getResultList();

When I tried that , I can't find setParamaterList() method .
 
Davide Crudo
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, my bad. The setParameterList seems not to be available in the EntityManager,
you could use hibernate in your Bean:

The setParameterList is available, but in the Hibernate Query (instead of the javax.Persistence package).

You would then need to get the SessionFactory injected and retrieve the hibernate session:

 
Space pants. Tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic