-->
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: Sub Object Collection filling.
PostPosted: Mon Oct 22, 2012 6:32 am 
Newbie

Joined: Mon Oct 22, 2012 6:10 am
Posts: 1
Hello All,

I have one problem related to Many-to-many mapping. I will try to explain it.
following is my User hbm file and it has groups mapping.
Code:
<hibernate-mapping auto-import="true" default-lazy="false">
    <class name="test.User" table="USER">
        <id name="id" type="java.lang.Integer" column="ID">
            <generator class="increment" />
        </id>
        <property name="username" type="java.lang.String" column="USERNAME" not-null="true" length="50"/>
         <set name="groups" table="USER_HAS_GROUP" inverse="true" fetch="join" lazy="true">
            <key column="USER_ID" />
            <many-to-many column="GROUP_ID" class="test.Group" />
        </set>
    </class>
</hibernate-mapping>


and this is Group HBM file
Code:
<hibernate-mapping auto-import="true" default-lazy="true">
    <class name="test.Group" table="GROUP">
        <id name="id" type="java.lang.Integer" column="ID">
        </id>
        <property name="designation" type="java.lang.String" column="DESIGNATION" not-null="true" length="255"/>
       
        <set name="users" table="USER_HAS_GROUP" lazy="true" cascade="all">
            <key column="GROUP_ID" />
            <many-to-many column="USER_ID" class="test.User" />
        </set>
     
    </class>
</hibernate-mapping>

and this is the user_has_group hbm file
Code:
<hibernate-mapping auto-import="true" default-lazy="false">
   <class name="test.UserHasGroup" table="USER_HAS_GROUP">
       <composite-id>
             <key-many-to-one class="test.Group" column="GROUP_ID" name="group"/>
            <key-many-to-one class="test.User" column="USER_ID" name="user"/>
        </composite-id>
      <property column="STATUS_NUMBER" length="10" name="status_number" not-null="true" type="integer" />
   </class>
</hibernate-mapping>


when I will get the User object using Hibernate Session it is firing the queries for Group --> Users collections as well...
Is there any provision in hibernate API so i can avoid this. Any help would be really appreciated.


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.