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: Mapping two collection properties to the same table
PostPosted: Tue Sep 19, 2006 1:26 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 4:10 pm
Posts: 38
Location: Charleston, SC
I'm trying to determine how or if I can map two different collections to the same table. I have a TaskForceAgenda object which has two collection properties: personnelAssignments and resourceAssignments. Both collections contain the same type of member class: TaskForceAssignment.

The TaskForceAssignment has two associations: one to a TaskForceMember and one to a TaskForceResource. In the personnelAssignments collection, the TaskForceResource property of TaskForceAssignment is null. In the resourceAssignments collection, the TaskForceMember property of TaskForceAssignment is null. I'd like to map both collections to the same table in such a way that when I load the TaskForceAgenda object, the two collections are mutually exclusive. Does Hibernate support this type of mapping or must I map the two collecitons to separate tables? My environment is hibernate 3.1 and SQL Server.

My TaskForceAgenda mapping file is included. It currently maps the two collections to separate tables. I'd like to modify it so that both collections are mapped to the same table and when loaded neither collection contains elements from the other collection.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="gov.seahawk.model">
    <!-- Hibernate class mapping -->
    <class name="TaskForceAgenda" table="TASK_FORCE_DAILY_AGENDA" dynamic-insert="true" dynamic-update="true">
        <id name="key" column="ID" type="string">
            <generator class="guid"/>
        </id>

        <property name="date" type="date" column="AGENDA_DATE"/>

        <set name="personnelAssignments" table="DAILY_PERSONNEL_ASSIGNMENTS" lazy="false" cascade="all">
            <key column="AGENDA_ID"/>
            <many-to-many class="TaskForceAssignment" column="PERSONNEL_ASSIGNMENT_ID" />
        </set>

        <set name="personnelStatuses" table="DAILY_PERSONNEL_STATUSES" lazy="false" cascade="all">
            <key column="AGENDA_ID" />
            <many-to-many class="TaskForceMember" column="PERSONNEL_STATUS_ID" >
            </many-to-many>
        </set>

        <set name="resourceAssignments" table="DAILY_RESOURCE_ASSIGNMENTS" lazy="false" cascade="all">
            <key column="AGENDA_ID" foreign-key="DAILY_RESOURCE_ASSIGNMENTS_AGENDA_ID_FK"/>
            <many-to-many class="TaskForceAssignment" column="RESOURCE_ASSIGNMENT_ID" />
        </set>

        <set name="resourceStatuses" table="DAILY_RESOURCE_STATUSES" lazy="false" cascade="all">
            <key column="AGENDA_ID" />
            <many-to-many class="TaskForceResource" column="RESOURCE_STATUS_ID" />
        </set>
    </class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="gov.seahawk.model">
    <class name="TaskForceAssignment" table="TASK_FORCE_ASSIGNMENT" dynamic-insert="true" dynamic-update="true">
        <id name="key" column="ID" type="string">
            <generator class="guid"/>
        </id>

        <property name="assignment" type="string" column="ASSIGNMENT" length="100"/>
        <property name="taskForceUnit" type="string" column="TASK_FORCE_UNIT" length="10"/>
        <property name="regularHours" type="float" column="REGULAR_HOURS"/>
        <property name="overtimeHours" type="float" column="OVERTIME_HOURS"/>

        <many-to-one
                name="member"
                class="TaskForceMember"
                column="TASK_FORCE_MEMBER_ID"
                cascade="none"
                lazy="false" />

        <many-to-one
                name="resource"
                class="TaskForceResource"
                column="TASK_FORCE_RESOURCE_ID"
                cascade="none"
                lazy="false" />
    </class>
</hibernate-mapping>



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.