-->
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.  [ 1 post ] 
Author Message
 Post subject: key-many-to-one problem in composite-id
PostPosted: Wed Jul 28, 2004 10:48 am 
Newbie

Joined: Wed Jul 28, 2004 10:14 am
Posts: 1
I am on Hibernate 2.1.4 and Sybase 12.5.

I want to use Hibernate on a old database bad-designed, and I have problems to make my mapping files.

The problem concern 3 tables :
- One of the table have an id with two key-property,
- the other one is classic and have only one column as id.
- The id of the last one is composed by the id of the first one (2 columns) and the id of the second one.

Mapping Documents :

GROUPEIHM.hbm :
Code:
<hibernate-mapping package="XXX.userin">
<class name="GroupeIHM" table="GROUPEIHM">
<composite-id name="id" class="GroupeIHMPK">
  <key-property name="groNum" column="GROnum" type="java.lang.Integer"/>
  <key-property name="cliId" column="CLIid" type="java.lang.Integer"/>
</composite-id>
...
</class>
</hibernate-mapping>


UTILISATEUR.hbm
Code:
<hibernate-mapping package="XXX.userin">
<class name="Utilisateur" table="UTILISATEUR">
<id
name="utiId"
type="java.lang.Long"
column="UTIid"
>
<generator class="increment"/>
</id>
...
</class>
</hibernate-mapping>


GROUPE_UTILISATEUR.hbm
Code:
<hibernate-mapping package="XXX.userin">
<class name="GroupeUtilisateur" table="GROUPE_UTILISATEUR">
<composite-id name="id" class="GroupeUtilisateurPK">
  <key-many-to-one name="id" class="GroupeIHMPK">
    <column name="GROnum"/>
    <column name="CLIid"/>
  </key-many-to-one>
  <key-many-to-one name="utiId" column="UTIid" class="Utilisateur"/>
</composite-id>
</class>
</hibernate-mapping>


I have this Exception :
Code:
net.sf.hibernate.MappingException: An association from the table GROUPE_UTILISATEUR refers to an unmapped class: XXX.GroupeIHMPK
   at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:661)
   at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:761)
   at com.prosodie.swingreactinv3.database.userin.dao._RootDAO.initialize(_RootDAO.java:33)
   at com.prosodie.swingreactinv3.login.HibernateTest.main(HibernateTest.java:31)


When I change this section :
Code:
<key-many-to-one name="id" class="GroupeIHMPK">
    <column name="GROnum"/>
    <column name="CLIid"/>
</key-many-to-one>

INTO this :
Code:
<key-property name="groNum" column="GROnum" type="java.lang.Integer"/>
<key-property name="cliId" column="CLIid" type="java.lang.Integer"/>


it's ok... but I lost the notion of foreign key... (isn't it ?)
Is anyone have an idea ?


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

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.