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.