-->
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.  [ 3 posts ] 
Author Message
 Post subject: Only get one element for a one-to-many relationship
PostPosted: Mon Dec 05, 2005 5:42 pm 
Newbie

Joined: Tue Oct 28, 2003 10:33 am
Posts: 9
Hibernate: 3.1rc1
Hibernate annotations: 3.1beta6
Database: MySQL4.1

I'm using a fetch join for a one-to-many relationship with lazy loading, e.g. searched by collection element property. Supposed, one customer has several orders. When I submit a named query to retrieve customers and load their orders orders too as follows:

SELECT customer
FROM Customer customer LEFT JOIN FETCH customer.orders order
WHERE order.orderDate = :orderDate

If I check the orders for a customer of the customer list, I can get only one order regardless the customer may have more than one order.

Any hint is appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 10:28 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 11:36 pm
Posts: 22
Is your orderDate property really just a date, or a datetime or timestamp? You may want to use some of the date functions here to make sure you are only refining the search down to the same day and not the same hour/minute/second:

http://www.hibernate.org/hib_docs/v3/re ... xpressions

_________________
Useful? Hit me with a point! Completely off base? Ya, well, what do you expect from a newbie...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 11:50 pm 
Newbie

Joined: Tue Oct 28, 2003 10:33 am
Posts: 9
Sorry, the search condition may be confusing. Let's say, Order has a property 'label', now it becomes this,

SELECT customer
FROM Customer customer LEFT JOIN FETCH customer.orders order
WHERE order.label= :label


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