-->
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: many-to-one Repeated Column Mapping Exception
PostPosted: Thu Apr 29, 2004 10:48 pm 
Newbie

Joined: Thu Apr 29, 2004 10:36 pm
Posts: 3
I am very new to hibernate and I am having a problem trying to do a basic map for a many-to-one relationship. Basically I have two tables:

1) A Department table with pk of department_id
2) A User table with a fk of department_id

When I try to map the relation in the user xml file, hibernate throws the following:

21:45:10,741 INFO Configuration:1080 - instantiating and configuring caches
21:45:10,991 INFO SessionFactoryImpl:119 - building session factory
Exception in thread "main" net.sf.hibernate.MappingException: Repeated column in
mapping for class com.sc.mis.data.MisUser should be mapped with insert="false"
update="false": ROLE_ID
at net.sf.hibernate.persister.AbstractEntityPersister.checkColumnDuplica
tion(AbstractEntityPersister.java:1003)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.jav
a:820)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(Pers
isterFactory.java:41)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.ja
va:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.
java:750)
at com.sc.mis.session.MisSessionFactory.<init>(MisSessionFactory.java:39
)
at com.sc.mis.session.MisSessionFactory.getInstance(MisSessionFactory.ja
va:46)
at com.sc.mis.test.TestMisBuilding.testSelect(TestMisBuilding.java:22)
at com.sc.mis.test.TestMisBuilding.main(TestMisBuilding.java:16)

Here is a copy of my mapping document:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sc.mis.data.MisUser" table="MIS_USER">
<id column="USER_ID" name="id" type="long">
<generator class="net.sf.hibernate.id.TableHiLoGenerator"/>
</id>

<set name="misLocations">
<key column="USER_ID"/>
<one-to-many class="com.sc.mis.data.MisLocation"/>
</set>

<many-to-one name="misDepartment" column="DEPARTMENT_ID"/>
<many-to-one name="misRole" column="ROLE_ID"/>

<property column="ROLE_ID" length="18" name="roleId" not-null="true" type="long"/>
<property column="DEPARTMENT_ID" length="18" name="departmentId" not-null="true" type="long"/>
<property column="ACTIVE" length="1" name="active" not-null="true" type="byte"/>
<property column="FIRST_NAME" length="255" name="firstName" type="string"/>
<property column="LAST_NAME" length="255" name="lastName" type="string"/>
<property column="UID" length="50" name="uid" type="string"/>
<property column="PHONE" length="50" name="phone" type="string"/>
<property column="EMAIL" length="255" name="email" type="string"/>
<property column="EMERGENCY_PHONE" length="50" name="emergencyPhone" type="string"/>
</class>
</hibernate-mapping>

Any suggestions would be greatly appreciated.
Thanks,
D


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Either of these mappings is correct, not the use of insert="false" update="false":


Code:
<hibernate-mapping>
<class name="com.sc.mis.data.MisUser" table="MIS_USER">
    <id column="USER_ID" name="id" type="long">
        <generator class="net.sf.hibernate.id.TableHiLoGenerator"/>
    </id>

    <set name="misLocations">
        <key column="USER_ID"/>
        <one-to-many class="com.sc.mis.data.MisLocation"/>
    </set>

    <many-to-one name="misDepartment" insert="false" update="false" column="DEPARTMENT_ID"/>
    <many-to-one name="misRole"  insert="false" update="false" column="ROLE_ID"/>
       
    <property column="ROLE_ID" length="18" name="roleId" not-null="true" type="long"/>
    <property column="DEPARTMENT_ID" length="18" name="departmentId" not-null="true" type="long"/>
    <property column="ACTIVE" length="1" name="active" not-null="true" type="byte"/>
    <property column="FIRST_NAME" length="255" name="firstName" type="string"/>
    <property column="LAST_NAME" length="255" name="lastName" type="string"/>
    <property column="UID" length="50" name="uid" type="string"/>
    <property column="PHONE" length="50" name="phone" type="string"/>
    <property column="EMAIL" length="255" name="email" type="string"/>
    <property column="EMERGENCY_PHONE" length="50" name="emergencyPhone" type="string"/>
</class>
</hibernate-mapping>



Code:
<hibernate-mapping>
<class name="com.sc.mis.data.MisUser" table="MIS_USER">
    <id column="USER_ID" name="id" type="long">
        <generator class="net.sf.hibernate.id.TableHiLoGenerator"/>
    </id>

    <set name="misLocations">
        <key column="USER_ID"/>
        <one-to-many class="com.sc.mis.data.MisLocation"/>
    </set>

    <many-to-one name="misDepartment" column="DEPARTMENT_ID"/>
    <many-to-one name="misRole" column="ROLE_ID"/>
       
    <property column="ROLE_ID" length="18" name="roleId" not-null="true" type="long" insert="false" update="false"/>
    <property column="DEPARTMENT_ID" length="18" name="departmentId" not-null="true" type="long" insert="false" update="false"/>
    <property column="ACTIVE" length="1" name="active" not-null="true" type="byte"/>
    <property column="FIRST_NAME" length="255" name="firstName" type="string"/>
    <property column="LAST_NAME" length="255" name="lastName" type="string"/>
    <property column="UID" length="50" name="uid" type="string"/>
    <property column="PHONE" length="50" name="phone" type="string"/>
    <property column="EMAIL" length="255" name="email" type="string"/>
    <property column="EMERGENCY_PHONE" length="50" name="emergencyPhone" type="string"/>
</class>
</hibernate-mapping>


Or you could simply remove the unnecessary roleId and departmentId properties:


Code:
<hibernate-mapping>
<class name="com.sc.mis.data.MisUser" table="MIS_USER">
    <id column="USER_ID" name="id" type="long">
        <generator class="net.sf.hibernate.id.TableHiLoGenerator"/>
    </id>

    <set name="misLocations">
        <key column="USER_ID"/>
        <one-to-many class="com.sc.mis.data.MisLocation"/>
    </set>

    <many-to-one name="misDepartment" column="DEPARTMENT_ID"/>
    <many-to-one name="misRole"  column="ROLE_ID"/>
       

    <property column="ACTIVE" length="1" name="active" not-null="true" type="byte"/>
    <property column="FIRST_NAME" length="255" name="firstName" type="string"/>
    <property column="LAST_NAME" length="255" name="lastName" type="string"/>
    <property column="UID" length="50" name="uid" type="string"/>
    <property column="PHONE" length="50" name="phone" type="string"/>
    <property column="EMAIL" length="255" name="email" type="string"/>
    <property column="EMERGENCY_PHONE" length="50" name="emergencyPhone" type="string"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:37 pm 
Newbie

Joined: Thu Apr 29, 2004 10:36 pm
Posts: 3
Thanks for the quick response. You solution worked great.
D


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.