I know there are several similar questions on the list, but I've been unsuccessful in twisting them into a solution for my particular problem.
I am using XML mapping files for my hibernate3 configuration. I need to create a group of unidirectional relations between a base object and multiple attachment objects. (The attachments can connect to multiple sites on the base object and each attachment point can hold many attachments. I need to track the lists of attachments separately.) But, doing this I get a "Repeated column in mapping for entity" exception.
org.hibernate.MappingException: Repeated column in mapping for entity: ATTACHMENT column: attachmentID (should be mapped with insert="false" update="false")
The part that is confusing me is that the base object mapping only uses the "attachmentID" as the list index, not the selection key.
Can anyone tell me how to set up these mapping files to avoid the exception? The other similar questions I've found answered on this forum all use annotation, but I need to use the XML.
This is my attachment object. It identifies 3 different kinds of attachment points. One base object type has two possible attachment points and the other has only one. When it attaches to one of the base points it gets the ID of that base object in the appropriate object ID and the rest are set to -1 (which is a special base record).
(Of course, these mappings are radically pared down, but I think I captured all the import features.)
<?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>
<class name="attachment" table="ATTACHMENT">
<id column="attachmentID" name="attachmentID" type="int">
<generator class="identity"></generator>
</id>
<property name="idBase1"></property>
<property name="idBase2"></property>
<property name="idAltBase1"></property>
</class>
</hibernate-mapping>
This is the mapping file for the base object.
<?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>
<class name="base" table="BASE">
<id column="IDBASE" name="idBase" type="int">
<generator class="identity"></generator>
</id>
<property name="type"></property>
<list name="attachment1" cascade="all">
<key column="idBase1" not-null="true" />
<list-index column="attachmentID" base="0" />
<one-to-many class="ATTACHMENT"/>
</list>
<list name="attachment2" cascade="all">
<key column="idBase2" not-null="true"/>
<list-index column="attachmentID" base="0" />
<one-to-many class="ATTACHMENT"/>
</list>
</class>
</hibernate-mapping>
and this is the mapping file for the alternate base object. It looks the same as the primary base object but only has one list of attachments. And, I think this one is ok. Or, at least, the exceptions are not being thrown by this mapping.
<?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>
<class name="altBase" table="BASE">
<id column="IDBASE" name="idBase" type="int">
<generator class="identity"></generator>
</id>
<property name="type"></property>
<list name="idAltBase1" cascade="all">
<key column="idBase1" not-null="true" />
<list-index column="attachmentID" base="0" />
<one-to-many class="ATTACHMENT"/>
</list>
</class>
</hibernate-mapping>