-->
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: Outer join with Criteria
PostPosted: Fri Jun 24, 2005 4:27 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
My question is very simple: how can I have a "left outer join" instead of that "inner join" using Criteria and createAlias, or something similar?
Is it possible somehow?

Regards
Alessandro

Hibernate version:
3.0.5
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 1.1//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="testHib3.tstDACmain" table="tst_main">
<id column="id" name="id" type="long">
<generator class="native"></generator>
</id>
<property column="des" length="50" name="des" not-null="false" type="string"/>
<many-to-one name="externStd" column="id_extern_std" class="testHib3.tstDACExternStd"
cascade="none" outer-join="false" not-null="false"/>
</class>
<class name="testHib3.tstDACExternStd" table="tst_extern_std" lazy="true">
<id column="id" name="id" type="long">
<generator class="native"></generator>
</id>
<property column="des" length="50" name="des" not-null="false" type="string"/>
</class>
</hibernate-mapping>

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

Criteria crit = hibSession.createCriteria(tstDACmain.class)
.createAlias("this.externStd", "ex");
List res = crit.list();

Full stack trace of any exception that occurs:
No exception

Name and version of the database you are using:
Not meaningfull

The generated SQL (show_sql=true):
Hibernate: select this_.id as id1_, this_.des as des0_1_, this_.id_extern_std as id3_0_1_, ex1_.id as id0_, ex1_.des as des1_0_, ex1_.id as id1_0_ from tst_main this_ inner join tst_extern_std ex1_ on this_.id_extern_std=ex1_.id


Top
 Profile  
 
 Post subject: Re: Outer join with Criteria
PostPosted: Fri Jun 24, 2005 8:28 am 
Newbie

Joined: Tue Dec 16, 2003 12:02 pm
Posts: 14
Location: Geneva, Switzerland
arizzi wrote:
My question is very simple: how can I have a "left outer join" instead of that "inner join" using Criteria and createAlias, or something similar?
Is it possible somehow?

<many-to-one name="externStd" column="id_extern_std" class="testHib3.tstDACExternStd"
cascade="none" outer-join="false" not-null="false"/>



what about having

outer-join="true"

in your mapping definition ?


Top
 Profile  
 
 Post subject: Re: Outer join with Criteria
PostPosted: Fri Jun 24, 2005 8:50 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
iphan wrote:
arizzi wrote:
My question is very simple: how can I have a "left outer join" instead of that "inner join" using Criteria and createAlias, or something similar?
Is it possible somehow?

<many-to-one name="externStd" column="id_extern_std" class="testHib3.tstDACExternStd"
cascade="none" outer-join="false" not-null="false"/>



what about having

outer-join="true"

in your mapping definition ?


I've tried with both outer-join="false" and outer-join="true", but the query is always done with INNER JOIN.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 1:25 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Outer join isn't supported in the Criteria API unfortunately, if you see some digging you will find some threads which discuss this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 1:29 pm 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
VampBoy wrote:
Outer join isn't supported in the Criteria API unfortunately, if you see some digging you will find some threads which discuss this.


Any plans to implement it?
It seems a big limit for the Criteria API, if I can use it just for reading a single table, without joins, it's almost useless.


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.