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.