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: Selecting a sub-class in a super-class collection
PostPosted: Thu Feb 03, 2011 11:20 am 
Newbie

Joined: Thu Jul 10, 2008 1:30 pm
Posts: 1
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?


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.