-->
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: Hibernate creates a column based on the foreign key
PostPosted: Tue Oct 12, 2004 8:56 pm 
Newbie

Joined: Tue Oct 12, 2004 5:56 pm
Posts: 3
Suppose there are two tables:

DEPT table
DEPTNO (pk)
DNAME
LOC

EMP table
EMPNO (pk)
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTID (fk references dept.deptno)

then here are my bidirectional mappings

Emp.hbm.xml
<hibernate-mapping>

<class name="de.gloegl.road2hibernate.Emp" table="EMP">
<id name="empno" column="EMPNO" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="ename" column="ENAME" type="string"/>
<property name="job" column="JOB" type="string"/>
<property name="mgr" column="MGR" type="long"/>
<property name="hiredate" column="HIREDATE" type="date"/>
<property name="sal" column="SAL" type="long"/>
<property name="comm" column="COMM" type="long"/>
<property name="deptid" column="DEPTID" type="long"/>
<many-to-one name="dept"
class="de.gloegl.road2hibernate.Dept"
column="deptno"/>
</class>

</hibernate-mapping>

Dept.hbm.xml
<hibernate-mapping>

<class name="de.gloegl.road2hibernate.Dept" table="Dept">
<id name="deptno" column="DEPTNO" type="long">
<generator class="native"/>
</id>
<property name="dname" column="DNAME" type="string"/>
<property name="loc" column="LOC" type="string"/>
<set name="employees" cascade="all" inverse="true" lazy="true">
<key column foreign-key="deptid"/>
<one-to-many class="de.gloegl.road2hibernate.Emp"/>
</set>
</class>

</hibernate-mapping>

So, when I try to load the Emp or Dept object, the Hibernate just creates a new column called deptno for me in the EMP table.

Can anybody know what the mapping should be done differently. We can not change the schema. I mean the foreign key deptid in the EMP table can not be renamed to deptno.

Thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 2:18 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
In the EMP mapping

delete
Code:
<property name="deptid" column="DEPTID" type="long"/>


change
Code:
<many-to-one name="dept"
class="de.gloegl.road2hibernate.Dept"
column="deptno"/>

to
Code:
<many-to-one name="dept"
class="de.gloegl.road2hibernate.Dept"
column="deptid"/>


HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 1:59 pm 
Newbie

Joined: Tue Oct 12, 2004 5:56 pm
Posts: 3
It does help. Thanks to Ernst.


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.