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?