-->
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.  [ 2 posts ] 
Author Message
 Post subject: composite-id & join table
PostPosted: Tue Nov 29, 2005 12:42 pm 
Newbie

Joined: Tue Nov 29, 2005 12:05 pm
Posts: 1
J'utilise Hibernate sur des tables d'une base patrimoniale DB2/AS400 et je cherche à regrouper des données de plusieurs tables dans une classe.
Les clés primaires de ces tables sont basées sur plusieurs colonnes, d'où l'utilisation du composite-id.

Est-il possible d'utiliser un des éléments du composite-id pour faire une jointure vers une table n'ayant pas les 2 éléments comme clé primaire?

Pour être plus clair voici un exemple :
Comment charger le libelle de SANAP10 sachant que le code de SAN7P10 : N7CPRD correspond au code de SANAP10 : NACPRG?


Hibernate version: 3.0.2

Mapping documents:
<class name="mysql.test.MyClass" table="SAN7P10">

<composite-id name="maPK" class="mysql.test.MyClassPK">
<key-property name="code" column="N7CPRD" />

<key-property name="id" column="N7NCON" />
</composite-id>

...

<join table="SANAP10" >
<key column="NACPRG" />

<property name="libelle" column="NALNPR" type="java.lang.String" />
</join>

Code between sessionFactory.openSession() and session.close():
session.get(MyClass.class, myClassPK);

Full stack trace of any exception that occurs:
1) testFormula(mysql.test.MySQLTest)java.lang.ExceptionInInitializerError
at mysql.test.MySQLTest.testFormula(MySQLTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at mysql.test.MySQLTest.main(MySQLTest.java:35)
Caused by: java.lang.RuntimeException: Problème de configuration : Foreign key (codeProduit:SANAP10 [NACPRG])) must have same number of columns as the referenced primary key (SAN7P10 [N7CPRD,N7NCON])
at mysql.test.HibernateUtil.<clinit>(HibernateUtil.java:16)
... 17 more
Caused by: org.hibernate.MappingException: Foreign key (codeProduit:SANAP10 [NACPRG])) must have same number of columns as the referenced primary key (SAN7P10 [N7CPRD,N7NCON])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:953)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:898)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1049)
at mysql.test.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 17 more

Name and version of the database you are using:
MySQL 4.1


Top
 Profile  
 
 Post subject: Re: composite-id & join table
PostPosted: Thu Sep 16, 2010 3:48 am 
Newbie

Joined: Tue Sep 14, 2010 6:04 am
Posts: 5
5 years later....

Bonjour,

Notre vieux BDD a 2 tables EMPLOYES et EMPLOYES2 avec le me^me couple de key:
- employesCode
- numero

J'arrive pas a join 2 tables vers une seule java classe Employes, car join n' accepte qu'une key.

Avez vous une idee?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.