-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem: Attributes in relation-tables
PostPosted: Mon May 10, 2004 4:23 am 
Newbie

Joined: Mon May 10, 2004 4:00 am
Posts: 3
Hi,

I have some trouble mapping a existing database to hibernate.
Currently there exists a set of tables looking like:

table1:
<id1><data1>

table2:
<id2><data2>

relation1:
<relation_id><id1><id2><attribute>

it is a many-to-many-relation.
Mapping the relation without the attribute is no problem, but i have no idea how-to add the attribute to the mapping.

I am using a idbag to do the mapping.

-----
for table1:
<idbag name="collectionname" table="relation1" cascade="all-delete-orphan"
lazy="false">
<collection-id type="int" column="relation_id">
<generator class="increment" />
</collection-id>
<key column="id1" />
<many-to-many column="id2"
class="className" />
</idbag>
------

perhaps anyone can give me a hint.

cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 5:21 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
You can use a composite-element as a collection value. This is explained in the doc, and there are various options. One possibility is the following:

Code:
        <set name="relatedPartiesTo" lazy="true" inverse="true" table="PARTY_RELATIONSHIP">
            <key column="PARTY_ID_FROM"/>
            <composite-element class="it.esselunga.ecommerce.data.model.PartyRelationship">
                <property name="fromDate" column="FROM_DATE" type="java.sql.Timestamp" />
                <property name="throughDate" column="THRU_DATE" type="java.sql.Timestamp" />
                <property name="description" column="DESCRIPTION" type="java.lang.String" length="100" />
                <many-to-one name="relationshipType" class="it.esselunga.ecommerce.data.model.PartyRelationshipType">
                    <column name="RELATIONSHIP_TYPE_ID"/>
                </many-to-one>
                <many-to-one name="relatedParty" class="it.esselunga.ecommerce.data.model.Party" column="PARTY_ID_TO"/>
            </composite-element>
        </set>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 11:33 am 
Newbie

Joined: Mon May 10, 2004 4:00 am
Posts: 3
Hi again,

i build my mapping like said above. But this created new problem:
When i don't create the mapping class ("PartyRelationship") in your example i'll get the error "no persister found for ...".
Ok so i created the class. But then the error "Batch run 0...insert into ( relation_id) values( Execution canceled..."

perhaps you can give me some more information how you create your classes etc.

cheers


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 11:57 am 
Newbie

Joined: Mon May 10, 2004 4:00 am
Posts: 3
Just found a solution:
i had to turn of cascading for the unmapped class (*Relationship here) and turn it on for the many-to-one relations.


cheers


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.