-->
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.  [ 6 posts ] 
Author Message
 Post subject: Criteria Order
PostPosted: Mon Aug 28, 2006 6:36 pm 
Newbie

Joined: Tue Apr 18, 2006 9:36 pm
Posts: 6
Location: Los Angeles, CA
Hibernate version:
Hibernate 3

Name and version of the database you are using:
Oracle 9

I would like to join several tables using Criteria. I want the objects returned -- no lazy loading. I only want the this query to be no lazy loading, therefore changing the mapping file is not an option.

I have attempted to perform this query in two ways.
First way:
Code:
Criteria custDetailCriteria = session.createCriteria(Customer.class);

custDetailCriteria.setFetchMode("customerPostalAddressSet",
                FetchMode.JOIN);

custDetailCriteria.setFetchMode(
                "customerPostalAddressSet.postalAddress", FetchMode.JOIN);

This allows me to get all of the information and it is not lazy loaded. However, I am unable to add an order by for addressLine1 (in postalAddress table). It give me an error that addressLine1 is not a property of customer.

Second way:
Code:
Criteria custDetailCriteria = session.createCriteria(Customer.class);

custDetailCriteria.createAlias("customerPostalAddressSet", "customerPostalAddress").setFetchMode("customerPostalAddress", FetchMode.JOIN);
custDetailCriteria.createAlias("customerPostalAddress.postalAddress", "postalAddress").setFetchMode("postalAddress", FetchMode.JOIN);
 
custDetailCriteria.addOrder(Order.asc("postalAddress.addressLine1"));


This second way allows me to do the order by, but does not turn lazy loading to off. I get a lazy loading initialization error on a different tier when I am trying to run a print statement. I can in debug, that the data has not been loaded.

Am I missing something? How can I combine the two so that I am able to add the order by and get all the data?


Top
 Profile  
 
 Post subject: ...
PostPosted: Tue Aug 29, 2006 12:24 pm 
Newbie

Joined: Tue Aug 29, 2006 12:17 pm
Posts: 2
I have the same problem...

crit.CreateAlias(aux[0],"orderby_")
.AddOrder(Order.Asc("orderby_."+aux[1]));

I use this, to compose criteria but the hibernate don't find the join connection.

Help me.... Please


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 5:20 pm 
Regular
Regular

Joined: Sat Nov 06, 2004 5:20 pm
Posts: 54
Location: Collierville, TN
cmodic, if your second scenario works and you are getting a lazy exception error on another tier, then add a setFetchMode to get to that tier and you should be good.

I don't think I've ever tried to "ORDER" on an attribute outside the DISTINCT_ROOT_ENTITY.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 1:45 pm 
Newbie

Joined: Tue Apr 18, 2006 9:36 pm
Posts: 6
Location: Los Angeles, CA
Quote:
if your second scenario works and you are getting a lazy exception error on another tier, then add a setFetchMode to get to that tier and you should be good.


When I say tier I mean, outside of the data tier. When the data is returned to another layer of the application (ie. a different class) and I try to access it, then it gives me a lazy loading error on customerPostalAddress, which I have done a setFetchMode on.

Any other ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 10:45 am 
Regular
Regular

Joined: Sat Nov 06, 2004 5:20 pm
Posts: 54
Location: Collierville, TN
Sorry - been away for a while.

If you've added a setFetchMode on customerPostalAddress and you are still getting a lazy exception when accessing it in a class - see if customerPostalAddress has a relationship to another table on which you are trying to access from the class but have not added a setFetchMode.

e.g. customerPostalAddress.country


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 5:16 pm 
Newbie

Joined: Tue Apr 18, 2006 9:36 pm
Posts: 6
Location: Los Angeles, CA
The only other tables that it access are lookup tables.

I am able to do order by for items in the customer (root) object, with no problem (no lazy loading initializaiton errors), but if I try to perform the order by on the postal address table, I get lazy loading initialization different tables.

Thank you,


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