Friday, January 18, 2013

Hibernate inconsistent mapping problem

I met following exception during changing hibernate mapping. I'm using hibernate 3.2

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: cz.koroptev.cubiculus.core.model.Brick column: id_shape (should be mapped with insert="false" update="false")
 at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:605)
 at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:627)
 at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:645)
 at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:420)
 at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
 at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
 at cz.koroptev.cubiculus.core.services.impl.HibernateManagerServiceImpl.(HibernateManagerServiceImpl.java:28)
 ... 47 more
Problem was in inconsistent mapping of relations ship between objects 'Shape' and 'Brick'. Object 'Shape' contain set of bricks mapped as:
  <set name="bricks" lazy="true" order-by="id_brick" >
   <key column="id_shape" not-null="true" />
   <one-to-many class="Brick" />
  </set>
and 'Brick' contains mapping to 'Shape'
  <many-to-one name="shape" class="Shape" column="id_shape"
   foreign-key="brick_shape" not-null="false" />
Problem is that in first mapping is column 'id_shape' mapped as not-null="true" and in second is mapped as not-null="false". This lead to mentioned exception.

No comments:

Post a Comment