-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Criteria Collection property (subquery?)
PostPosted: Wed Dec 28, 2011 9:35 am 
Newbie

Joined: Wed Dec 28, 2011 9:26 am
Posts: 1
Hello

I am not very familiar with Hibernate Criteria, and apologize if this question is too simple... However, any help is greatly appreciated!

I have two entities, CD and Track. Each CD has collection of Track-objects. In each Track there is a String-field named "title". Now I want to retrieve, using Hibernate Criteria all CDs having a Track with "title" set to a certain value. What I have so far is this:

Code:
//session handling
Criteria cdCriteria = session.createCriteria(CD.class);
DetachedCriteria trackCriteria = DetachedCriteria.forClass(Track.class);
trackCriteria.add(Restrictions.eq("title", "SomeTitle"));
trackCriteria.setProjection(Projections.property("title"));
criteria.add(Subqueries.exists(trackCriteria));
List<CD> cds = criteria.list();


This returns all cds, regardless of track title. Does anybody have any suggestions?

Thank you in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.