-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: problem with Hibernate3 <join>
PostPosted: Tue Oct 26, 2004 2:33 pm 
Newbie

Joined: Mon Oct 25, 2004 5:21 pm
Posts: 6
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 2:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Creating a JIRA entry for this in the Hibernate3 subproject would be good. - this might be a bug


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 3:08 pm 
Newbie

Joined: Mon Oct 25, 2004 5:21 pm
Posts: 6
I created a JIRA entry, any additional help would be great.

also, I noticed that the hibernate3 DTD does not allow a joined-subclass to use the <join> tag. I am guessing this is a design decision, as it doesn't seem necessary (although could, in some cases, make mappings easier), but I wanted to confirm this this was the case.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.