This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Querying Based On Member of Contained Collection

 
Jason Ferguson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic