Code:
public class OneRole {
private Set<ManyRole1> roles = new HashSet<ManyRole1>();
private String name;
private String flavor;
}
public class ManyRole {
private String name;
private String gender;
}
public class ManyRole1 extends ManyRole {
private double role1double;
}
public class ManyRole2 extends ManyRole {
private String role2string;
}
In mapping file I defined the following for class OneRole :
Code:
<set name="roles" cascade="all"
outer-join="true">
<key column="roleOneName"></key>
<one-to-many class="ManyRole1" />
</set>
while defined for class ManyRole:
Code:
<discriminator column="deiscriminator-value"/>
now tale "one-role" is for class OneRole and "many-role" is for ManyRole by using Table per class hierarchy strategy.
in DB: one-role table contains
-----------------------------------------
name | flavor <------ columns
---------------------------------------
andy | aFlavor <--------datas
while in many-role table
-----------------------------------------------------------------------
name | gender | roleOneName | discriminator-value <-columns
-----------------------------------------------------------------------
manyRoleName | M | andy | manyRole1
manyRoleName2 | M | andy | manyRole1
manyRoleName3 | F | andy | manyRole2
the problem is when I queried:
OneRole.getRoles() hibernate returns all the three rows in many-role table , but in real I just want it returns two rows:
manyRoleName | M | andy | manyRole1
manyRoleName2 | M | andy | manyRole1