-->
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: can't get expected resuts: one-to-many +Polymorphic
PostPosted: Thu May 15, 2008 4:27 am 
Newbie

Joined: Thu May 15, 2008 3:54 am
Posts: 1
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


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.