-->
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: Criteria API equivalent for HQL Query - search for orphans
PostPosted: Wed Feb 11, 2009 7:33 pm 
Newbie

Joined: Wed Feb 11, 2009 3:02 pm
Posts: 3
Hi,

My program has a pair of entity classes which represent a parent-child relationship (avoiding circular references). It also needs to support orphaned children. The entity classes are as follows (pseudocode)

Child.java:
Code:
@Entity
public class Child {
  //... property/method definitions and bean accessors
}

Parent.java:
Code:
@Entity
public class Parent {
   @ManyToMany
   private Set<Child> children;
   //... other property/method definitions and bean accessors
}

My DAO uses the following HQL query to get the orphaned children:
Code:
SELECT child FROM Child AS child WHERE child NOT IN (SELECT DISTINCT child FROM Parent AS parent INNER JOIN parent.children AS child)


The HQL query works exactly as I want it to. My question is, is there a way to do the same thing using the Criteria API?


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.