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 ?