-->
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: Mapper une jointure
PostPosted: Mon Jun 16, 2008 2:04 pm 
Newbie

Joined: Thu Jun 12, 2008 10:52 am
Posts: 16
Bonjour a tous,
Jai un probleme avec mon mapping. Voila ce qu'il se passe :

Jai une table T_CONTRACT et une table T_CLIENT. T_CONTRACT contient un id vers T_CLIENT (qui represente la personne qui a souscrit a ce contrat). Je voudrais faire une jointure entre ces 2 table afin de pouvoir ecrire quelques chose comme
Code:
Contract ct = ContractDAO.findById(1);
Client cl = ct.getFkSubscriber();


Pour l'instant j'ai ca :
Contract.hbm.xml
Code:
<hibernate-mapping package="dao.person">
    <class name="Contract" table="contract">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="identity" />
        </id>
        <property name="idSubscriber" type="int">
            <column name="ID_CLIENT" not-null="true" />
        </property>       
     
        <join table="CLIENT" inverse="true" optional="true">
           <key column="ID" unique="true"/>
           <many-to-one name="fkSubscriber" column="ID_CLIENT"
                class="dao.client.Client" not-null="true" unique="true"/>
        </join>
    </class>
</hibernate-mapping>

Client.hbm.xml
Code:
<hibernate-mapping package="dao.client">
    <class name="Cient" table="client">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="identity" />
        </id>
     ...
    </class>
</hibernate-mapping>

Mais ca ne marche pas du tout ... jai une exception de type sql syntax error.
Quelqu'un peut m'aider s'il vous plait ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 22, 2008 4:25 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
La class "Contract" doit être mappée comme suit:

Code:
<hibernate-mapping package="dao.person">
    <class name="Contract" table="contract">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="identity" />
        </id>

        <many-to-one name="fkSubscriber" not-null="true" column="ID_CLIENT"/>
    </class>
</hibernate-mapping>


Pour autant que ta classe Contract ait bien une méthode du style:

Client getFkSubscriber();

Dans ce cas, Hibernate a tout ce dont il a besoin pour effectuer le mapping (il connait la seconde table pour la jointure: il s'agit de la table sur laquelle mappe "Client")

(cfr. hibernate doc, chapitres 5.1.12 ou 5.1.13 si il s'agit d'un one-to-one)


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.