jQuery in Action, 2nd edition*
The moose likes EJB and other Java EE Technologies and the fly likes How do criteria API and subqueries work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How do criteria API and subqueries work?" Watch "How do criteria API and subqueries work?" New topic
Author

How do criteria API and subqueries work?

daniele licitra
Ranch Hand

Joined: Apr 08, 2013
Posts: 36

Hi to all.

I want to make a query using Criteria API. I use EclipseLink to auto-create metaclass. The query, in a jpql like syntax, is:


The java code I wrote is:


The query without the subquery works.

First problem:
in subquery, the table is called DN_THIS like the table in the main query. For example, the HAVING clause must be HAVING v.codtessera = a.codtessera, but the code
qpremio.having(cb.equal(vendcod, card.get(Anagraficacard_.codtessera)));
produces
HAVING (DN_THIS.codtessera = DN_THIS.codtessera)

How do I specify two different name for two different entity/table? Is there something wrong?

Second problem:
the query must be
WHERE ... AND (subquery) >= 20
How do I create a predicate like that? I haven't found any example
I need a predicate because i specify filter by a jsf mask with a lot of filter-options that need also other subqueries.

Thanks in advance


JPA 2.1.0
Glassfish 3.1->4, Wildfly, Primefaces 3.4->4
 
 
subject: How do criteria API and subqueries work?
 
Similar Threads
Cannot find symbol error in switch-case
Help with this code.
Unnecessary INNER JOIN with Criteria
Too few parameters. Expected 3
Help with a Query!!!!