aspose file tools*
The moose likes Object Relational Mapping and the fly likes Criteria with IN clause that comes from a sub sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria with IN clause that comes from a sub sql" Watch "Criteria with IN clause that comes from a sub sql" New topic
Author

Criteria with IN clause that comes from a sub sql

Dheeman Basu
Greenhorn

Joined: Mar 17, 2009
Posts: 12
How do I create IN Restriction using sub query?

Here are my tables
Table A ( primary_key_a, vala1, vala2, ....... )
Table B ( primary_key_b, foreign_key_a, valb1, valb2, ..........)

I want to select records from table B ( mapped in hibernate by BeanB) with certain foreign_key_a values ( say the ones with vala1 = 5, select primary_key_a where vala1 = 5)

My Hibernate code:
Session session = sessionFactory.openSession();
Criteria crit = session.createCriteria(BeanB.class);
crit.Restriction.in( "foreign_key_a" <some code> );

How do I fit in select primary_key_a where vala1 = 5 for <some code> ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Criteria with IN clause that comes from a sub sql