-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL Selection through <many-to-one> causes wrong join
PostPosted: Fri Mar 31, 2006 9:28 am 
Newbie

Joined: Tue Jul 12, 2005 5:41 am
Posts: 7
Hello,

I'm querying with HQL and selecting one field from a Source class and another from an instance of a Target class belonging to a <many-to-one> in Source called "t". Since the target could be null (and I'd like the Source rows come back anyway), I would expect an SQL outer join when this query gets translated, but I get an inner one, so I don't get back the rows that have the foreign key == null. I'm using a non-lazy "join" fetch strategy.

Hibernate version: 3.1.3

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="hibtest.Source">
      <id name="key">
         <generator class="uuid"/>
      </id>
      <property name="i"/>
      <many-to-one name="t" class="hibtest.Target" fetch="join" lazy="false"/>
   </class>
   <class name="hibtest.Target">
      <id name="key">
         <generator class="uuid"/>
      </id>
      <property name="s"/>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
            Session s = sf.getCurrentSession();
            Transaction t = s.beginTransaction();
            Query q = s.createQuery("select s.i, s.t.s from hibtest.Source s");
            List l = q.list();
            t.commit();
            System.out.println(l.toString());



Name and version of the database you are using: MySQL 5

The generated SQL (show_sql=true):

Code:
select source0_.i as col_0_0_, target1_.s as col_1_0_ from Source source0_, Target target1_ where source0_.t=target1_.key


Could you help me here please? If you need the java classes or other info please just ask.

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 02, 2006 8:49 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Could you try the HQL

select s.i, targ.s
from hibtest.Source s left jojn s.t targ

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 3:41 am 
Newbie

Joined: Tue Jul 12, 2005 5:41 am
Posts: 7
Thank you very much fo your reply.

Yes it works, but it is not clear to me why it shouldn't work the other way around... Pls consider that, since I am _generating_ code starting from a model to use Hibernate, it is very difficult for me to use this kind of query (it would be another particular case in the generator).

Do you have any clue about why it is not working without the explicit outer join? Reading the manual/docs/FAQs/forums didn't help me so far.

TIA.


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