-->
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 proxies
PostPosted: Mon Sep 11, 2006 4:26 pm 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Hi.

I always thought that object identity is equivalent to database identity within the context of a session. So two objects can be compared using == if they represent the same database row AND they are loaded in the same session.

I've learned there is an exception when inheritance is involved (http://www.hibernate.org/hib_docs/reference/en/html_single/#performance-proxies). But I was surprised to see that == breaks when an object with a proxy is fetched again via a subsequent query. The scenario I've got is:

1) Object A is loaded via lazy-loading in a session.
2) Object B is eagerly fetched via an association in HQL.

In reality, object A and object B point to the same database row, and the same session was used for step 1 and 2. But A != B because A is a proxy and B is not. Could someone explain why Hibernate didn't create a reference to the same proxy in step 2? Are there other cases in which == breaks within a session?

If it matters, I'm using Hibernate 2.1. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 10:29 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
I just reread the section on object identity in HiA (section 4.1.4) and now I'm more confused. I don't see any exceptions to the "object identity is equivalent to database identity within a session" rule. Is the behavior I'm seeing above a bug then? Thanks.


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.