-->
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.  [ 2 posts ] 
Author Message
 Post subject: Question about Joins
PostPosted: Mon May 19, 2008 4:52 pm 
Newbie

Joined: Thu Jan 24, 2008 1:35 am
Posts: 9
Hello:

In the tables below I have a Many to Many relationship between Group and Role. GroupRole does the linking between these tables.

In the objects below, is it necessary to use the intermediary object to facilitate the linking?

ie: In the Group object I have a collection of
Code:
<set name="groupRoles" cascade="all-delete-orphan" lazy="true" inverse="true">


* Does this have to GroupRoles or can I have a collection Roles and if so, how would I do that?

Ultimately, I would like to expose my pojo's as web services. However, because I have Role object in Group and Group object in Role, I am creating a circular reference. How do most people avoid this?

thanks for you help.


Group

Code:
   <class name="Group" table="GRP" >

        <comment></comment>
        <id name="grpId" type="string">
            <column name="GRP_ID" length="20" />
            <generator class="assigned" />
        </id>
        <property name="grpName" type="string">
            <column name="GRP_NAME" length="40">
                <comment></comment>
            </column>
        </property>

        <property name="companyId" type="string">
            <column name="COMPANY_ID" length="20">
                <comment></comment>
            </column>
        </property>
        <property name="parentGrpId" type="string">
            <column name="PARENT_GRP_ID" length="20">
                <comment></comment>
            </column>
        </property>

        <property name="groupClass" type="string">
            <column name="GROUP_CLASS" length="40">
                <comment></comment>
            </column>
 
        <set name="groupRoles" cascade="all-delete-orphan" lazy="true" inverse="true">
            <key>
                <column name="GRP_ID" length="20" not-null="true">
                    <comment></comment>
                </column>
            </key>
            <one-to-many class="GroupRole" />
        </set>
               
    </class>




Role

Code:
<hibernate-mapping>
    <class name="Role" table="ROLE" >
        <comment></comment>
        <id name="roleId" type="string">
            <column name="ROLE_ID" length="20" />
            <generator class="assigned" />
        </id>
        <property name="serviceId" type="string">
            <column name="SERVICE_ID" length="20">
                <comment></comment>
            </column>
        </property>
        <property name="roleName" type="string">
            <column name="ROLE_NAME" length="40">
                <comment></comment>
            </column>
        </property>

        <set name="grpRoles" fetch="select" cascade="all-delete-orphan">
            <key>
                <column name="ROLE_ID" length="20" not-null="true">
                    <comment></comment>
                </column>
            </key>
            <one-to-many class="GroupRole" />
        </set>
     
    </class>
</hibernate-mapping>


GroupRole


Code:
<hibernate-mapping>
    <class name="GroupRole" table="GRP_ROLE" >
        <comment></comment>
        <id name="grpRoleId" type="string">
            <column name="GRP_ROLE_ID" length="20" />
              <generator class="SequenceGenerator">
                 <param name="table">sequence_gen</param>
                 <param name="column">next_id</param>
                 <param name="attribute">GRP_ROLE_ID</param>
               </generator>
        </id>

        <many-to-one name="role" class="Role" fetch="select">
            <column name="ROLE_ID" length="20" not-null="true">
                <comment></comment>
            </column>
        </many-to-one>
        <many-to-one name="group" class="Group" fetch="select">
            <column name="GRP_ID" length="20" not-null="true">
                <comment></comment>
            </column>
        </many-to-one>


        <property name="serviceId" type="string">
            <column name="SERVICE_ID" length="20" not-null="true">
                <comment></comment>
            </column>
        </property>       

    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 6:15 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
Quote:
I am creating a circular reference. How do most people avoid this?


you don't need to make the relationship bidirectional.

If you use serialized entities you don't need to be concerned with circularity.

Quote:
In the objects below, is it necessary to use the intermediary object to facilitate the linking?

Yes you need the intermediate object because of SERVICE_ID in your bridge table; if you didn't have properties on the link you could avoid the extra entity.

kind regards,

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.