File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Querying Based On Member of Contained Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Querying Based On Member of Contained Collection" Watch "Querying Based On Member of Contained Collection" New topic
Author

Querying Based On Member of Contained Collection

Jason Ferguson
Ranch Hand

Joined: Aug 09, 2007
Posts: 58
Okay, given the following class:



In my code, I'll create and persist Employee objects like this:



But later, I'd like to query for a particular Employee.


This doesn't work, because Restrictions.in() expects a String for the field name and a collection.

Maybe I'm overlooking something, but how can I query based on whether a certain object is contained in a persisted object's member collection?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Basically, you want to restrict based on an attribute in the related object.

So you use a Join and then you can add the joined objects attribute in the restriction.

To do a join in a Criteria object is with the addAlias() method of Criteria.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Querying Based On Member of Contained Collection