Converting an existing non-hibernate app to Hibernate. (3.0)
I need to re-use a column for both the index and as a property in a composite element (see the ObjName column/property in this example):
Mapping documents:
Code:
<hibernate-mapping default-lazy="false">
<class name="MyClass" table="MYCLASSTABLE">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property ..../>
<map name="MySubObj" table="SUBOBJ">
<key column="MYCLASSID"/>
<index column="OBJNAME" type="string"/>
<composite-element class="MySubObj">
<property name="ObjName" column="OBJNAME"/>
<property ..../>
<property ..../>
<property ..../>
</composite-element>
</map>
</class>
</hibernate-mapping>
Hibernate gives an exception when processing the mapping docs:
Code:
org.hibernate.MappingException: Repeated column in mapping for collection: MyClass.MySubObj column: OBJNAME
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:290)
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:313)
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:987)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1147)
at <my app>
So as a work-around, I change the map to a set and have taken out the <index column="OBJNAME".../> line from the mapping file.
Is there anyway to keep this as a map? In my workaround, I'm converting to/from a map in the [get/set]MySubObj( Set set) getter/setter pair.
This works kinda okay, but I'm getting a lot of re-writing of the set in the SUBOBJ db table that I'm assuming is caused by me not preserving Hibernate's original set.
-Trevor