Hi all,
I am using Naked Objects framework that generates a mapping file representing a one to many reflexive association (in this very case from class MyClass to itself).
How to avoid the MappingException due to
Repeated column in mapping for collection?
Thanks
Hibernate version: Code:
3.0
Name and version of the database you are using: Code:
MySQL 5.0.51
Mapping file:Code:
<?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="org.yourdomainapp.MyClass" table="MYCLASS" lazy="false">
<id name="id" column="PKmyclassID" type="long" access="org.nakedobjects.nos.store.hibernate.property.OidAccessor">
<generator class="native"/>
</id>
<version name="naked_version" type="long" access="org.nakedobjects.nos.store.hibernate.property.VersionAccessor" column="version"/>
<property name="naked_modified_by" type="string" access="org.nakedobjects.nos.store.hibernate.property.UserAccessor" column="modified_by"/>
<property name="naked_modified_on" type="timestamp" access="org.nakedobjects.nos.store.hibernate.property.TimestampAccessor" column="modified_on"/>
<property name="title" column="title" type="string" access="org.nakedobjects.nos.store.hibernate.property.TitleAccessor"/>
<bag access="field" name="children" table="MYCLASS_MYCLASS" inverse="true" lazy="false">
<key column="FKmyclass"/>
<many-to-many class="org.yourdomainapp.MyClass" column="FKmyclass"/>
</bag>
<property type="java.lang.String" name="name" column="name"/>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:Code:
[java] 0 [NakedObjectsSystem main ERROR] failed to intialise
[java] org.hibernate.MappingException: Repeated column in mapping for collection: org.yourdomainapp.MyClass.children column: FKmyclass
[java] at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:306)
[java] at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:329)
[java] at org.hibernate.mapping.Collection.validate(Collection.java:286)
[java] at org.hibernate.cfg.Configuration.validate(Configuration.java:1106)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
[java] at org.nakedobjects.nos.store.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:243)
[java] at org.nakedobjects.nos.store.hibernate.HibernateUtil.isInitialized(HibernateUtil.java:531)
[java] at org.nakedobjects.nos.store.hibernate.HibernateUtil.init(HibernateUtil.java:507)
[java] at org.nakedobjects.nos.store.hibernate.HibernateObjectStore.init(HibernateObjectStore.java:393)
[java] at org.nakedobjects.nof.persist.objectstore.ObjectStorePersistor.init(ObjectStorePersistor.java:160)
[java] at org.nakedobjects.nof.core.persist.ObjectPersistorLogger.init(ObjectPersistorLogger.java:110)
[java] at org.nakedobjects.nof.boot.system.NakedObjectsSystem.init(NakedObjectsSystem.java:430)
[java] at org.nakedobjects.nof.boot.NakedObjects.run(NakedObjects.java:216)
[java] at org.nakedobjects.nof.boot.NakedObjects.main(NakedObjects.java:75)
[java] Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for collection: org.yourdomainapp.MyClass.children column: FKmyclass
[java] at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:306)
[java] at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:329)
[java] at org.hibernate.mapping.Collection.validate(Collection.java:286)
[java] at org.hibernate.cfg.Configuration.validate(Configuration.java:1106)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
[java] at org.nakedobjects.nos.store.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:243)
[java] at org.nakedobjects.nos.store.hibernate.HibernateUtil.isInitialized(HibernateUtil.java:531)
[java] at org.nakedobjects.nos.store.hibernate.HibernateUtil.init(HibernateUtil.java:507)
[java] at org.nakedobjects.nos.store.hibernate.HibernateObjectStore.init(HibernateObjectStore.java:393)
[java] at org.nakedobjects.nof.persist.objectstore.ObjectStorePersistor.init(ObjectStorePersistor.java:160)
[java] at org.nakedobjects.nof.core.persist.ObjectPersistorLogger.init(ObjectPersistorLogger.java:110)
[java] at org.nakedobjects.nof.boot.system.NakedObjectsSystem.init(NakedObjectsSystem.java:430)
[java] at org.nakedobjects.nof.boot.NakedObjects.run(NakedObjects.java:216)
[java] at org.nakedobjects.nof.boot.NakedObjects.main(NakedObjects.java:75)
[java] Java Result: 1