[Hibernate 3] Mapper une jointure
Bonjour, je dois intervenir de toute urgence pour faire fonctionner un petit outil en Hibernate 3. Je rencontre une exception pour faire la jointure de deux tables, sachant que je ne dois pas utiliser HQL.
J'ai deux tables : PERPHY et DENOMPHY. La clé primaire de PERPHY est IDITIP, donc DENOMPHY a IDITIP pour clé étrangère. La relation entre ces deux tables est du many-to-one : une seule instance de PERPHY a au moins une instance de DENOMPHY
Je voudrais simplement programmer en Java une simple jointure. En donnant cette clé IDITIP, je veux obtenir toutes les informations des deux tables. En outre, je voudrais modéliser la requête SQL suivante :
Code:
1 2 3
|
select * from denomphy d, perphy p
where p.IDITIP = d.IDITIP |
Voici donc les fichiers pour le mapping, sachant que j'ai supprimé les balises property très nombreuses :
Perphy.hbm.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="metier.Perphy" table="PERPHY">
<id name="IDITIP" column="IDITIP"/>
<property name="CDACTIF"/>
...
</class>
</hibernate-mapping> |
Denomphy.hbm.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="metier.Denomphy" table="DENOMPHY">
<id name="IDITIP" column="IDITIP"/>
<property name="NOSEQ"/>
...
<many-to-one name="FK_DPHY_PHY_IDITIP" column="IDITIP" not-null="true"/>
</class>
</hibernate-mapping> |
Maintenant le problème, quand je lance le tout, j'ai droit à une exception :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Initial SessionFactory creation failed.org.hibernate.MappingException: Error reading resource: Denomphy.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at HibernateUtil.<clinit>(HibernateUtil.java:20)
at Principale.chercheDenomPhy(Principale.java:31)
at Principale.main(Principale.java:22)
Caused by: org.hibernate.MappingException: Error reading resource: Denomphy.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
at HibernateUtil.<clinit>(HibernateUtil.java:16)
... 2 more
Caused by: org.hibernate.PropertyNotFoundException: field not found: FK_DPHY_PHY_IDITIP
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:96)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:103)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:111)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:90)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:78)
at org.hibernate.mapping.ToOne.setTypeUsingReflection(ToOne.java:57)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:1841)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1827)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1728)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:318)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:236)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
at org.hibernate.cfg.Configuration.add(Configuration.java:362)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
... 9 more |
En outre, il me dit qu'il ne sait pas ce qu'est FK_DPHY_PHY_IDITIP. Il s'agit dans le modèle de donnés du nom de la jointure entre les deux, a priori, ce n'est pas ce qu'il faut mettre...
Quelqu'un pourrait-il me dépanner et me dire ce qu'il faut mettre à la place.
Ensuite, comment dois-je coder ma jointure en Java ? J'ai bien les deux classes Java correspondantes, mais que faire ensuite ?
Autant je fais du Struts, c'est ma première expérience en Hibernate...
Merci par avance de votre aide.