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:
|