-->
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: Problems with OneToOne relationship and complex query
PostPosted: Mon Dec 10, 2007 10:06 pm 
Newbie

Joined: Mon Dec 10, 2007 9:34 pm
Posts: 1
I have three classes:

Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class A {

  @Id @GeneratedValue
  private Long id;

  @Column
  int state;

}

@Entity
public class B extends A {

   @ManyToOne(optional = false, fetch = FetchType.EAGER)
   @JoinColumn(nullable = false)
   private C c;
}

@Entity
public class C extends A {
   @OneToMany(fetch = FetchType.EAGER, mappedBy = B.c, cascade = CascadeType.ALL)
   private List<B> b;
}


I now need to perform a query to retrieve all instances of C where the state field for any of its related B's is equal to a specific value. The native SQL would look something like this:

Code:
select C.* from C, B where C.b_id = B.id and B.state = ?


Is this possible? I've tried various forms of Constraints and haven't been able to figure out how to reference the state field of my nested object.


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.