Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
I have a one-to-many between two legacy DB tables.
The two tables have the same column name "CREDIT_REF_NUM"
It is he primary key in CREDIT_APP table (one) and part of composite key in associated table DOC (many).
CREDIT_APP table
CREDIT_REF_NUM - PK
DOC table
CREDIT_REF_NUM - PK, FK
FORM_ID - PK
I'm getting "org.hibernate.MappingException: Repeated column in mapping for collection: com.domain.application.Application.documents column: CREDIT_REF_NUM
"
Tha stack trace is bellow also.
I guess the use of
formula='CREDIT_REF_NUM' would work but composite-map-key does not allow it.
Hibernate version:
3.1.2
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="com.domain.application">
<class
name="Application"
table="CREDIT_APP"
lazy="true"
abstract="false">
<id
name="referenceNumber"
type="com.persistence.hibernate.usertype.ReferenceNumberUserType"
column="CREDIT_REF_NUM">
<generator class="assigned" />
</id>
<timestamp
name="updateTimestamp"
unsaved-value="null"
column="TSTAMP">
</timestamp>
<map
name="documents"
cascade="all-delete-orphan"
lazy="true"
table="DOC"
inverse="true">
<key not-null="true">
<column
name="CREDIT_REF_NUM"
not-null="true">
</column>
</key>
<composite-map-key class="com.domain.application.DocumentKey">
<key-property
name="referenceNumber"
column="CREDIT_REF_NUM"
type="com.persistence.hibernate.usertype.ReferenceNumberUserType">
</key-property>
<key-property
name="formId"
column="FORM_ID"
type="com.persistence.hibernate.usertype.StringToCharUserType">
</key-property>
</composite-map-key>
<one-to-many
class="com.domain.application.DocumentImpl" />
</map>
</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="com.domain.application">
<class
name="DocumentImpl"
table="DOC"
abstract="false"
lazy="true">
<composite-id
name="DocumentKey"
class="com.domain.application.DocumentKey">
<key-property
name="referenceNumber"
type="com.persistence.hibernate.usertype.CreditReferenceNumberUserType"
column="CREDIT_REF_NUM"/>
<key-property
name="formId"
type="com.persistence.hibernate.usertype.StringToCharUserType"
column="FORM_ID"/>
</composite-id>
<timestamp
name="updateTimestamp"
unsaved-value="null"
column="PRINTED_TSTAMP">
</timestamp>
<property
name="updateUserID"
type="com.persistence.hibernate.usertype.StringToCharUserType"
column="PRINTED_BY_USER_ID"
not-null="true">
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
org.hibernate.MappingException: Repeated column in mapping for collection: com.domain.application.Application.documents column: CREDIT_REF_NUM
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:290)
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:303)
at org.hibernate.mapping.Collection.validate(Collection.java:270)
at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:67)
at org.hibernate.cfg.Configuration.validate(Configuration.java:988)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
Name and version of the database you are using:
DB2 8.1.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: