-->
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: Mapping:Same number of columns as the referenced primary key
PostPosted: Tue May 04, 2004 5:59 am 
Newbie

Joined: Tue May 04, 2004 5:51 am
Posts: 3
PROBLEM DESCRIPTION
===================

I have two tables (each have composite keys). One
composit key is a subset of the other one. I get
following message error during mapping processing:

net.sf.hibernate.MappingException: Foreign key
(ROLE_ABSENCE [ABSENCETYPE_VERSIONID])) must have same
number of columns as the referenced primary key
(ABSENCETYPE [ID,VERSIONID])

at
net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)

at
net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:667)

at
net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:761)

at
com.test.java.dao._RootDAO.initialize(_RootDAO.java:33)

at com.test.testclient.Test.main(Test.java:14)


Has someone become a successfull mapping for a
comparable problem?

Thanks in advance!


DATABASE SCHEMA
===============

TABLE: absencetype | with composite id (id,versionid)
- id
- versionid
- column_1
- column_2


TABLE: role_absence | with composite id
(role_id,role_versionid,absencetype_id,absencetype_versionid)
- role_id
- role_versionid
- absencetype_id (foreign key to absencetype)
- absencetype_versionid (foreign key to absencetype)
- column_a
- column_b


MAPPING FILES (generated by Hibernate Synchronizer)
=============

ABSENCETYPE.hbm:
----------------

...
<class name="ABSENCETYPE" table="ABSENCETYPE">
<composite-id name="id" class="ABSENCETYPEPK">
<key-property name="id" column="ID" type="integer"/>
<key-property name="versionid" column="VERSIONID" type="integer"/>
</composite-id>
...


RoleAbsence.hbm:
----------------

...
<class name="RoleAbsence" table="ROLE_ABSENCE">
<composite-id name="id" class="RoleAbsencePK">
<key-property name="roleId" column="ROLE_ID" type="integer"/>
<key-property name="roleVersionid" column="ROLE_VERSIONID" type="integer"/>
<key-many-to-one name="absencetype" column="ABSENCETYPE_ID" class="ABSENCETYPE"/>
<key-many-to-one name="absencetypeVersionid" column="ABSENCETYPE_VERSIONID" class="ABSENCETYPE"/>
</composite-id>
...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 11:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<class name="RoleAbsence" table="ROLE_ABSENCE">
<composite-id name="id" class="RoleAbsencePK">
<key-property name="roleId" column="ROLE_ID" type="integer"/>
<key-property name="roleVersionid" column="ROLE_VERSIONID" type="integer"/>
<key-many-to-one name="absencetype" class="ABSENCETYPE">
  <column name="ABSENCETYPE_ID"/>
  <column name="ABSENCETYPE_VERSIONID"/>
</key-many-to-one>
</composite-id>

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Tip works fine!!!
PostPosted: Fri May 07, 2004 2:34 pm 
Newbie

Joined: Tue May 04, 2004 5:51 am
Posts: 3
Thank you very much emmanuel! Actually, that would be a imperfection on Hibernate synchronizer :( Despite of that, it's a great tool to retrieve the basic mapping files, and refine it with tips on this forum and the tutorial on this site.


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.