-->
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: DetachedCriteria inner join or left join
PostPosted: Tue May 29, 2007 11:00 pm 
Newbie

Joined: Sun Sep 19, 2004 9:23 pm
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:hibernate3.1.2

Name and version of the database you are using:SQL 2000

Code:
DetachedCriteria detachedCriteria = DetachedCriteria
            .forClass(SysOrganization.class,"sysorg");

         detachedCriteria.createAlias("OOrgUsers", "ru");
         detachedCriteria.createAlias("ru.sysUser", "sysuser");
if (state == null || state.equalsIgnoreCase("true")){
            detachedCriteria.add(Restrictions.eq("sysorg.POrgCode", porgCode));
         }
         else{
            detachedCriteria.add(Restrictions.eq("sysorg.orgCode", new Long(porgCode)));
         }
         detachedCriteria.add(Restrictions.ne("sysorg.orgFlag", new Integer(0)));
         detachedCriteria.addOrder(Order.asc("sysorg.orgSortId"));

the sql is:
Code:
select top 10 this_.ORG_CODE as ORG1_1_2_, this_.P_ORG_CODE as P2_1_2_, this_.ORG_NAME as ORG3_1_2_,
this_.ORG_ABNAME as ORG4_1_2_, this_.ORG_PHONE as ORG5_1_2_, this_.ORG_MEMO as ORG6_1_2_, this_.ORG_FLAG as ORG7_1_2_,
this_.ORG_SORT_ID as ORG8_1_2_,
ru1_.OID as OID2_0_, ru1_.ORG_CODE as ORG2_2_0_, ru1_.USER_CODE as USER3_2_0_, ru1_.USER_ORG_FLAG as USER4_2_0_,
sysuser2_.USER_CODE as USER1_0_1_, sysuser2_.USER_ACCOUNT as USER2_0_1_, sysuser2_.USER_PWD as USER3_0_1_,
sysuser2_.USER_NAME as USER4_0_1_, sysuser2_.USER_MEMO as USER5_0_1_, sysuser2_.USER_FLAG as USER6_0_1_,
sysuser2_.USER_SORT_ID as USER7_0_1_ from EcodeWFM.dbo.SYS_ORGANIZATION this_
inner join EcodeWFM.dbo.O_ORG_USER ru1_ on this_.ORG_CODE=ru1_.ORG_CODE inner join EcodeWFM.dbo.SYS_USER sysuser2_ on ru1_.USER_CODE=sysuser2_.USER_CODE where this_.P_ORG_CODE=1000000000 order by this_.ORG_SORT_ID asc

why it is inner join insdead of left join?how to set it to left join.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 11:45 pm 
Newbie

Joined: Sun Sep 19, 2004 9:23 pm
Posts: 7
Code:
detachedCriteria.createAlias("OOrgUsers", "ru");   
detachedCriteria.createAlias("ru.sysUser", "sysuser");   

amend
Code:
detachedCriteria.setFetchMode("OOrgUsers", FetchMode.JOIN);   
            detachedCriteria.setFetchMode("sysUser", FetchMode.JOIN);   

that is connect,but why?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 4:28 am 
Newbie

Joined: Sun Sep 19, 2004 9:23 pm
Posts: 7
pls help me,thx


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 8:43 pm 
Newbie

Joined: Sun Sep 19, 2004 9:23 pm
Posts: 7
5555

Nobody can answer this question?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 1:04 pm 
Newbie

Joined: Mon Mar 10, 2008 12:55 pm
Posts: 2
Location: Gurgaon, India
I know this post is pretty old but since I spent quite some time trying to arrive at a solution, I think a reply here would help others who have the same issue...

DetachedCriteria does not have all methods that the Criteria has up until Hibernate 3.2.6

See http://opensource.atlassian.com/project ... At9ftUvEzI

The alterative is to use Criteria instead and use the createAlias(String associationPath, String alias, int joinType) method. This allows the join type to be explicitly mentioned while creating the alias.


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.