• Post Reply Bookmark Topic Watch Topic
  • New Topic

I want to use List<String> in JPQL syntaxis  RSS feed

 
Rufat Babakishiyev
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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;
}
 
Davide Crudo
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!