Two Laptop Bag*
The moose likes Object Relational Mapping and the fly likes Using Hibernate Criteria with an List within my domain object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Using Hibernate Criteria with an List within my domain object" Watch "Using Hibernate Criteria with an List within my domain object" New topic
Author

Using Hibernate Criteria with an List within my domain object

Craig Dumolien
Greenhorn

Joined: Nov 07, 2005
Posts: 20
I have a domain object Order, which has an List of OrderLine objects withing OrderLine, I have another object called Product which has fields I need to be able to search on.

I currently have Hibernate set up to pull all the Product and OrderLine data, when an Order is requested. I like this. However, when using criteria I thought I should be able to set this up like,

but I get an Exception: org.hibernate.QueryException: could not resolve property: orderLines.product.customerProductId of: com....domain.Order



Is my notation wrong? If I just do a search on the poNum (which resides on the Order object), the search works fine. It only has problems when I go down to the OrderLine and Product level.

Thanks for the help.
Trilochan Bharadwaj
Ranch Hand

Joined: Feb 02, 2009
Posts: 100
you can't go through properties like that, hibernate only "hydrates" one-to-one mapping for models, to go beyond that depth, you have to do something like:



or something in those lines.

Trilochan.
Craig Dumolien
Greenhorn

Joined: Nov 07, 2005
Posts: 20
Thanks for the input. That fixed it. The code I actually used is below. After getting the OrderLine, every other object I need to reference is one-to-one.

 
jQuery in Action, 2nd edition
 
subject: Using Hibernate Criteria with an List within my domain object
 
Similar Threads
Inconsistent stack height 2 != 1
Hibernate Search using Criteria with OR condition.
Problem in Query By Example (Hibernate)
Quering on multiple tables using criteria api
Search using Hibernate criteria querry