-->
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: Object identity and criteria parameters
PostPosted: Thu May 19, 2011 5:30 pm 
Newbie

Joined: Sun Apr 17, 2011 4:56 pm
Posts: 2
Let's say we have two classes Customer and Order that have a connection between them. One Customer may have zero, one or many Orders associated.

If I create a Criteria query to read the Orders of a specific Customer I would pass the Customer object as a parameter to the query. In the resulting set of Orders it seems that they are connected to another Customer object with the same data (i e a different object identity). This is not the behaviour I want in my app. What do I need to do to make it return the same Customer object connected to the Order(s)?

I have not implemented the equals() method of my classes (they are generated from EMF). Is this a factor here?
Is there any way I can configure Hibernate and/or my query to get my desired behaviour?
I am also using Teneo since I am using EMF, but to me this seems to be a Hibernate issue, not a Teneo issue.


Top
 Profile  
 
 Post subject: Re: Object identity and criteria parameters
PostPosted: Thu May 19, 2011 6:06 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hibernate will always guarantee that objects returned from the same session and having the same primary key will be the same instance (==).

That said, the entities must be returned by the Session and not provided by you. In the example you mentioned you should first load the Customer from Hibernate, then use it as parameter. Usually not a problem, as all entities are usually loaded by Hibernate.. so it's more likely that you should widen the scope of your Sessions.

_________________
Sanne
http://in.relation.to/


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.