-->
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: One to many relationship problem: duplicate collection role
PostPosted: Thu Sep 16, 2004 6:37 am 
Newbie

Joined: Thu Sep 16, 2004 6:06 am
Posts: 1
I am a total Hibernate newbie, trying to implement one to many collection, and encounter this problem, can any of you guys give me a helping hand?
In my case, one Receipt has many Receipt Items.
Is it the key mapping problem?

Hibernate version: 1.2.3


SQL table structures:
RECEIPT (ID)
RECEIPT_ITEM(RECEIPT_ID, LINE_NO)


Java entities:
public class Receipt {
private long id;
private Collection receiptItems = new ArrayList();
...
...
}

public class ReceiptItem {
private int lineNo;
private Receipt receipt;
...
...
}


Mapping documents:
Receipt.hbm.xml
<hibernate-mapping>
<class name="eg.Receipt"
table="RECEIPT">
<id name="id" type="long" column="ID" unsaved-value="0">
<generator class="native"/>
</id>

<bag role="receiptItems" readonly="true">
<key column="RECEIPT_ID"/>
<one-to-many class="eg.ReceiptItem"/>
</bag>
</class>
</hibernate-mapping>

ReceiptItem.hbm.xml
<hibernate-mapping>
<class name="eg.ReceiptItem" table="RECEIPT_ITEM">
<composite-id>
<key-property name="lineNo" type="integer" column="LINE_NO"/>
<key-property name="receipt" type="integer" column="RECEIPT_ID"/>
</composite-id>

<many-to-one name="receipt"
class="eg.Receipt"/>
</class>
</hibernate-mapping>


Part of the stack trace of any exception that occurs:
:18:24,578 ERROR [DatastoreImpl] Could not compile the mapping document
rrus.hibernate.MappingException: duplicate collection role: Receipt/receiptItems
at cirrus.hibernate.map.Root.addCollection(Root.java:162)
at cirrus.hibernate.map.PersistentClass.propertiesFromXML(PersistentClass.java:72)
at cirrus.hibernate.map.RootClass.<init>(RootClass.java:227)
at cirrus.hibernate.map.Root.<init>(Root.java:135)
at cirrus.hibernate.impl.DatastoreImpl.store(DatastoreImpl.java:106)
at cirrus.hibernate.impl.DatastoreImpl.storeInputStream(DatastoreImpl.java:116)
...
...


Name and version of the database you are using: IBM DB2 v7.1


Server: Jboss 3.0.1


The generated SQL (show_sql=true):


Debug level Hibernate log excerpt:


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.