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!