Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible to create this HQL equivalent using Hibernate Criteria?

 
James Cheng
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two following classes mapped in hibernate mappings

Class A1 {
long ID;
String t1;
String t2;
}
Class B1 {
long ID;
String t3;
String t4;
}

I am wondering if it's possible to create a HQL equivalent using criteria API
SELECT {a.*}
FROM A1 AS a, B1 AS b
WHERE a.t1 = b.t3 AND a.t2 = b.t4

I looked up "correlated subqueries" but I can't seem to figure out a correct way to do this as A1 and B1 are not linked by any FK constraints.
[ March 09, 2008: Message edited by: James Cheng ]
 
Ravi Kakani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate doesn't support outer joins on dynamic associations (not presented in mapping).

Look at Hibernate 3.1 - it is introduced new 'with' keyword:

You may supply extra join conditions using the HQL with keyword.

Hope this helps!
 
Allen Yu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply but what I need is to build such HQL using criteria, the HQL example works fine. I just want to create it using Criteria interface because I need to use this as a subquery for another Criteria.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic