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.