Hibernate version:
3.0 (latest from cvs)
Mapping documents:
ObjectItem.hbm.xml
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 package = "com.acs.crom">
<class name="ObjectItem" table="obj_item">
<!-- unique ID for class -->
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="obj_item_id" sql-type="bigint(15)" not-null="true"/>
<generator class="native"/>
</id>
<discriminator column="cat_code" type="string"/>
<!-- protected String categoryCode -->
<property name="categoryCode" type="java.lang.String" insert="false" update="false">
<column name="cat_code" sql-type="varchar(6)"/>
</property>
<!-- protected String name -->
<property name="name" type="java.lang.String">
<column name="name" sql-type="varchar(100)"/>
</property>
<!-- protected String alternateName -->
<property name="alternateName" type="java.lang.String">
<column name="alt-identific_txt" sql-type="varchar(255)"/>
</property>
<!-- protected ObjectStatus status -->
<many-to-one name="status" class="ObjectStatus" insert="false" update="false" cascade="all">
<column name="obj_item_id"/>
</many-to-one>
<!-- protected ObjectItemLocation objectItemLocation -->
<many-to-one name="objectItemLocation" class="ObjectItemLocation" insert="false" update="false" cascade="all">
<column name="obj_item_id"/>
</many-to-one>
<!-- join with obj_item_type -->
<join table="obj_item_type">
<key column="obj_item_id"/>
<!-- protected ObjectType type -->
<many-to-one name="type" class="ObjectType" cascade="all">
<column name="obj_type_id"/>
</many-to-one>
</join>
<!-- join with obj_item_capab -->
<join table="obj_item_capab">
<key column="obj_item_id"/>
<!-- protected Capability capability -->
<many-to-one name="capability" class="Capability" cascade="all">
<column name="capab_id"/>
</many-to-one>
</join>
</class>
</hibernate-mapping>
Feature.hbm.xml
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 package = "com.acs.crom">
<subclass name="Feature" extends="com.acs.crom.ObjectItem" discriminator-value="FE">
<join table="feat">
<!-- links id back to superclass -->
<key column="feat_id"/>
<!-- protected String featureCategoryCode -->
<property name="featureCategoryCode" type="java.lang.String">
<column name="cat_code" sql-type="char(6)"/>
</property>
</join>
</subclass>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():N/A
Full stack trace of any exception that occurs:Code:
13:39:28,732 ERROR SessionManager:34 - Initial SessionManager creation failed.
org.hibernate.MappingException: Repeated column in mapping for class com.acs.crom.Feature should be mapped with insert="false" update="false": cat_code
at org.hibernate.persister.BasicEntityPersister.checkColumnDuplication(BasicEntityPersister.java:2283)
at org.hibernate.persister.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:300)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:44)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:184)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:942)
at com.acs.hibernate.SessionManager.<clinit>(SessionManager.java:32)
at com.acs.bml.impl.HibernateLoadTest.main(HibernateLoadTest.java:25)
java.lang.ExceptionInInitializerError
at com.acs.hibernate.SessionManager.<clinit>(SessionManager.java:35)
at com.acs.bml.impl.HibernateLoadTest.main(HibernateLoadTest.java:25)
Caused by: org.hibernate.MappingException: Repeated column in mapping for class com.acs.crom.Feature should be mapped with insert="false" update="false": cat_code
at org.hibernate.persister.BasicEntityPersister.checkColumnDuplication(BasicEntityPersister.java:2283)
at org.hibernate.persister.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:300)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:44)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:184)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:942)
at com.acs.hibernate.SessionManager.<clinit>(SessionManager.java:32)
... 1 more
Exception in thread "main"
Name and version of the database you are using:
mySQL ver 12.22 distrib 4.0.21
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A
I am trying to map a complex database to a fairly different object model, and have needed to use the hibernate3 <join> tag frequently. It has been working well, up until this problem. Feature, a subclass of ObjectItem, joins the obj_item table to the feat table. The problem seems to be that each table has a cat_code field. Thus, when I map the cat_code field in the feat table, an error message states that this is a repeat mapping, when the only other time cat_code is referred to is in the obj_item table. It seems to me that hibernate is confusing the two. I don't know if the fact that cat_code in obj_item is a discriminator has something to do with this problem or not. I am not sure if I have caught a bug in hibernate3, or if I am doing something wrong. I know this is an ugly mapping, but unfortunately it needs to be done. Any help would be greatly appreciated.
Thanks,
Jeff