-->
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.  [ 5 posts ] 
Author Message
 Post subject: Multiple objects in a HQL query
PostPosted: Mon Feb 02, 2004 10:32 am 
Newbie

Joined: Mon Feb 02, 2004 10:12 am
Posts: 5
Hi,

I've got a problem with a query in HQL when I select multiple objects.
Sometimes, (and I don't know why) instead of getting in return of my query an array of Object[], I've only got the first object.

Of course I can get my second object by my first one with the relation between them, but obviouly it's not my favorite method.

I'm using Hibernate 2.1.1

There is my mapping and query :

Code:
<class name="...PtlTypeChambre" table="xpc_ptl_type_chambre">

   <composite-id name="xpcPK" class="...PtlTypeChambrePK">
      <key-property column="replique" name="replique" />
      <key-property column="code_exp" name="codeExp" />
      <key-property column="code_ptl" name="codePtl" />
      <key-property name="numTypeChambre" column="num_tpc" />
   </composite-id>

   <version name="version" column="num_version" />
   <property name="libTypeChambre" column="lib_tpc" />

   <set name="setTypesChambreJour" lazy="true" inverse="true" cascade="delete">
      <key>
         <column name="replique" />
         <column name="code_exp" />
         <column name="code_ptl" />
         <column name="num_tpc" />
      </key>
      <one-to-many class="..TypeChambreJour" />
   </set>

   <set name="setDotations" lazy="true" inverse="true" cascade="delete">
      <key>
         <column name="replique" />
         <column name="code_exp" />
         <column name="code_ptl" />
         <column name="num_tpc" />
      </key>
      <one-to-many class="...PtlDotation" />
   </set>

   <set name="setRatios" lazy="true" inverse="true" cascade="delete">
      <key>
         <column name="replique" />
         <column name="code_exp" />
         <column name="code_ptl" />
         <column name="num_tpc" />
      </key>
      <one-to-many class="...PtlRatio" />
   </set>
</class>


Code:
<class name="...TypeChambreJour" table="xtc_type_chambre_jour">

   <composite-id name="xtcPK" class="...TypeChambreJourPK">
      <key-property name="replique" column="replique" />
      <key-property name="codeExp" column="code_exp" />
      <key-property name="codePtl" column="code_ptl" />
      <key-property name="numTpc" column="num_tpc" />
      <key-property name="dateTcd" column="date_tcd" />
   </composite-id>

   <version name="version" column="num_version" />
   <property name="nbOccVeille" column="nb_occ_veille" />
</class>


The query :

Code:
select
   xpc, xtc
from
   PtlTypeChambre xpc
   left outer join fetch xpc.setTypesChambreJour xtc
where
   xpc.id.replique = 'A'
   and xpc.id.codeExp = 1
   and xpc.id.codePtl = 1


So if someone can explain where I'm wrong, I'd be pleased.
Thanks in advance.

Jerome


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 10:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you be more explicit on 'sometimes'.
PS since you use inverse="true", you need to add a many-to-one on the other side.
Read http://www.hibernate.org/Documentation/InsideExplanationOfInverseTrue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 10:57 am 
Newbie

Joined: Mon Feb 02, 2004 10:12 am
Posts: 5
Excuse me for the 'sometimes'. I've always got the problem with the query I submited. But with other queries there's no problem.

For the many-to-one end of the relation there is another problem. See this post http://forum.hibernate.org/viewtopic.php?t=925623
I'm using Sybase, and you can't have this piece of sql work :

Code:
select 1 as '1', 1 as '2'

So 2 columns, can't have the same alias. With hibernate, if I map the many-to-one, the key will be a subset of my primary key, and then the sql generated give twice the same alias for each property of my composite-id.

Another thing is that I'm using (maybe not in the good way) the inverse='true' for deleting in cascade all the relations of my object PtlTypeChambre.

I'm going to try without the inverse="true" and see, but I'm not sure this will work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As per the documentation, entities named in a LEFT JOIN FETCH clause do not appear in the result set.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 1:36 pm 
Newbie

Joined: Mon Feb 02, 2004 10:12 am
Posts: 5
Thank you very much !


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