Question about Hibernate Mapping (One-TO-Many)
while in my path to learn Hibernate i am struck at a point so need you suggestion. I have Three class A,B,C and there parent Class. These Three class are only represnting three aspect only but in the underlying Database being mapped to same Table.
In My parent class i have refrences to these three classes as
private Set<A> airTransport =new HashSet<A>();
private Set<B> roadTransport=new HashSet<B>();
private Set<C> trainTransport=new HashSet<C>();
and in the parent hbm file i have mapped them as
<set name="A" table="Test" inverse="true" lazy="true" cascade="save-update, delete"&g开发者_开发百科t;
<key>
<column name="PARENTID" />
</key>
<one-to-many class="A" />
</set>
<set name="B" table="TEST" inverse="true" lazy="true" cascade="save-update, delete">
<key>
<column name="PARENTID" />
</key>
<one-to-many class="B" />
</set>
<set name="C" table="TEST" inverse="true" lazy="true" cascade="save-update, delete">
<key>
<column name="PARENTID" />
</key>
<one-to-many class="C" />
</set>
i also have one more class which i have mapped as composite-element inside the three classes A,B and C
in my database i have three entries in Test table one for class A, one for class B and last one is for class C my table structure is
UUID
PARENTID
Other Fields
when i retrived my ParentClass Object it and checked the size of Set it gives me the following figures set for class A has 3 elements while B and C class's set have 1 element each and this is giving me problem while deleting the object.
i am clueless why this is behaving like the way. any idea/suggestion in this regard will be helpfull
You can use the 'where' attribute in the set xml element. You will need some way of discriminating which rows should be in each set. See http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html
example 7.6
精彩评论