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: Stored procedure and many-to-one relationship
PostPosted: Fri Jul 20, 2007 9:26 am 
Newbie

Joined: Fri Jul 20, 2007 9:18 am
Posts: 2
I've the following mapping files :

Code:
<hibernate-mapping>
  <class name="fr.suo.out.template.metier.Fournisseur" lazy="false">
    <id name="id" column="IDFOURNISSEUR"></id>
    <property name="code" column="CDFOURNISSEUR"/>
    <property name="libelle" column="LBFOURNISSEUR"/>   
  </class>
</hibernate-mapping>   


and

Code:
<hibernate-mapping>
  <class name="fr.suo.out.template.metier.Commande" lazy="false">
    <id name="id" column="IDCOMMANDE" ></id>
    <property name="code" column="CDCOMMANDE" />
    <property name="libelle" column="LBCOMMANDE" />   
    <many-to-one name="fournisseur" class="fr.suo.out.template.metier.Fournisseur" column="IDFOURNISSEUR" />
  </class>
</hibernate-mapping>   


I've a storage procedure which return all information (both commande and fournisseur) in one resulset.

I read hibernate forum but I didn't find a solution to instanciate commande and fournisseur with my stored procedure

Do you have a workaround (I know return-join don't work).

Thanks for your help.


Top
 Profile  
 
 Post subject: A solution to Stored procedure / many-to-one
PostPosted: Wed Aug 29, 2007 10:21 am 
Newbie

Joined: Fri Jul 20, 2007 9:18 am
Posts: 2
After many search, my colleague found a solution.

First case : one stored procedure for the "COMMANDE" and the "FOURNISSEUR" is loaded automatically by Hibernate (lazy or not lazy)

Code:

<sql-query name="prc.load.commande" callable="true">
    <return alias="COMMANDE" class="fr.suo.out.tutorial.metier.Commande">
       <return-property name="id" column="IDCOMMANDE" />
       <return-property name="code" column="CDCOMMANDE" />
       <return-property name="libelle" column="LBCOMMANDE" />
       <return-property name="dateCommande" column="DTCOMMANDE" />
       <return-property name="montant" column="MTCOMMANDE" />
       <return-property name="fournisseur" column="IDFOURNISSEUR" />      
  </return>
    <![CDATA[
       { call PRC_LOAD_COMMANDE(?) }
    ]]>
</sql-query>


Second case : only one stored procedure for the"COMMANDE" and the "FOURNISSEUR" :

Code:
   <sql-query name="prc.load.commande.fournisseur" callable="true">
       <return alias="COMMANDE" class="fr.suo.out.tutorial.metier.Commande">
            <return-property name="id" column="IDCOMMANDE" />
             <return-property name="code" column="CDCOMMANDE" />
             <return-property name="libelle" column="LBCOMMANDE" />
             <return-property name="dateCommande" column="DTCOMMANDE" />
             <return-property name="montant" column="MTCOMMANDE" />
             <return-property name="fournisseur" column="IDFOURNISSEUR" />
       </return>
       <return alias="FOURNISSEUR" class="fr.suo.out.tutorial.metier.Fournisseur">
            <return-property name="id" column="IDFOURNISSEUR" />
             <return-property name="code" column="CDFOURNISSEUR" />
             <return-property name="libelle" column="LBFOURNISSEUR" />
       </return>
       <![CDATA[
         { call PRC_LOAD_COMMANDE_FOURNISSEUR(?) }
      ]]>
   </sql-query>



The solution is in the row <return-property name="fournisseur" column="IDFOURNISSEUR" /> in the "return" mapping of the "fournisseur" property of the "COMMANDE" ojbect.

I hope it's help some body


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.