Folks,
I have the following classes (getters/setter ommited, other attributes that are not relevant also ommited):
Code:
@Entity
@Table(name = "A_CLASS")
public class AClass implements Serializable {
private static final long serialVersionUID = 6940459502248157282L;
@Id
@Column(name = "A_ID", precision = 22, scale = 0)
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rgd")
private Set<SuperClass> superCollection= new HashSet<SuperClass>(0);
}
Code:
@Entity
@Table(name="SuperClass")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class SuperClass implements Serializable{
private static final long serialVersionUID = 8600666101007360681L;
@Id
@Column(name="SUPER_ID", precision=22, scale=0)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="A_ID", nullable=false)
private AClass aClass;
}
Code:
@Entity
@Table(name="SUB_CLASS_B")
public class SubClassB extends SuperClass {
private static final long serialVersionUID = -8646039332033485546L;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "subClassB")
private Set<OtherClassC> otherClassCCollection = new HashSet<otherClassC>(0);
}
Code:
@Entity
@Table(name="OTHER_CLASS_C")
public class otherClassC implements Serializable {
private static final long serialVersionUID = -5706276552661131774L;
@Id
@Column(name="CLASS_C_ID", precision=22, scale=0)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="SUB_CLASS_B_ID", nullable=false)
private SubClassB subClassB;
}
Imagine that other classes could sub-class SuperClass (C, D, or whatever). Only SubClassB contains the Atribute otherClassCCollection.
As you can see, Class A has a collection of SuperClass.
My problem is:
My app must do a search for the A class, and one criteria is to match which instances of A contains an instance of SubClassB that contains a given instance of OtherClassC.
My trouble is that A has a list of SuperClass and I cannot search for the otherClassCCollection since it only exists in the SubClassB.
Any suggestion?