-->
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: Outer join problem with Criteria Query
PostPosted: Mon Nov 05, 2007 12:32 pm 
Newbie

Joined: Mon Nov 05, 2007 12:12 pm
Posts: 5
Hibernate version:Core Plugin 3.2.0.beta9

Name and version of the database you are using: PostgreSQL 8.2

The generated SQL (show_sql=true):
Code:
Hibernate: select this_.REPORT_ID as y0_ from CUSTOMERS this_ left outer join CUSTOMERSTATS customersi2_ on this_.CUSTOMER_ID=customersi2_.STAT_ID
Hibernate: select this_.uuid as y0_, this_.serialNum as y1_, this_.ipAddr as y2_, this_.operStatus as y3_, this_.label as y4_, cust2_.NICKNAME as y5_ from DEVICES this_ inner join REPORTS rep1_ on this_.REPORT_ID=rep1_.REPORT_ID inner join CUSTOMERS cust2_ on rep1_.CUSTOMER_ID=cust2_.CUSTOMER_ID left outer join CUSTOMERSTATS customersi7_ on cust2_.CUSTOMER_ID=customersi7_.STAT_ID inner join RAID_CONTROLLERS rs3_ on this_.DEVICE_ID=rs3_.DEVICE_ID where this_.REPORT_ID in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


Hi, I'm having trouble with a criteria query that i'm trying to execute. From the output above, you can see that there is an inner join on the "RAID_CONTROLLERS" table. I want this to be an outer join, and all the documentation that I have read indicates that a fetchmode of "join" is an outer join.

Here is the code that I am using to create my criteria.

Code:
final org.hibernate.Criteria gdCrit = dbSession.createCriteria(com.exagrid.triage.dbstor.GridDevice.class);

      final org.hibernate.Criteria custCrit = dbSession.createCriteria(com.exagrid.triage.dbstor.CustomerSite.class);
      final org.hibernate.criterion.ProjectionList custProjList = org.hibernate.criterion.Projections.projectionList();
      custProjList.add(org.hibernate.criterion.Projections.property("latestReport"));
      custCrit.setProjection(custProjList);

      final org.hibernate.criterion.ProjectionList projList = org.hibernate.criterion.Projections.projectionList();
      projList.add(org.hibernate.criterion.Projections.property("uuid"));
      projList.add(org.hibernate.criterion.Projections.property("serialNum"));
      projList.add(org.hibernate.criterion.Projections.property("ipAddr"));
      projList.add(org.hibernate.criterion.Projections.property("operStatus"));
      projList.add(org.hibernate.criterion.Projections.property("label"));

      gdCrit.createAlias("report", "rep");
      gdCrit.createAlias("rep.fromCustomer","cust");
      projList.add(org.hibernate.criterion.Projections.property("cust.nickname"),"nickname");

      gdCrit.createAlias("raidsets", "rs").setFetchMode("rs",org.hibernate.FetchMode.JOIN);

      gdCrit.setProjection(projList);
      gdCrit.add(org.hibernate.criterion.Restrictions.in("report",custCrit.list()));

final java.util.List < ? > qList = gdCrit.list();


Here is a bit from my mapping file that defines the set I'm trying to fetch:
Code:
<set name="raidsets" inverse="true" cascade="all" lazy="true">
         <meta attribute="field-description"> The raid controllers in this device </meta>
         <key column="DEVICE_ID" not-null="true" />
         <one-to-many class="com.exagrid.triage.dbstor.RaidController" />
      </set>


And finally, here's an SQL statement of exactly what I am looking for for the joining:
Code:
select devices.label, raid_disks.slot, raid_disks.serialnum
   from devices
      left outer join raid_controllers on (raid_controllers.device_id = devices.device_id) ,
            customers where devices.report_id = customers.report_id order by devices.label, raid_disks.slot;


I've searched the internet, and haven't come up with an answer for the behavior I'm seeing.
Thanks,
Shawn


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 14, 2007 1:18 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
I'm not sure what version it became available but there is a method on Criteria that will take join type.

criteria.createAlias(<Association>, <Alias>, Criteria.LEFT_JOIN);

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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.