> From: Gavin King [mailto:[EMAIL PROTECTED]
> 
> >  But if the
> > entity doesn't override equals, everything gets wacky because
equals()
> > is not reflexive:
> >
> > proxyA.equals(realA) != realA.equals(proxyA)
> 
> In the current implementation, it can only break if we have the same
> object twice, once as a proxy, and once as a direct reference. This
_is_
> kinda rare...

Map entityMap = getMapWithEntityKeys();
EntityA a = sess.load(EntityA.class, aId);
Object whatIWant = entityMap.get(a);

This doesn't seem terribly uncommon, I do it pretty frequently.  In any
system which uses entities for Map keys, it is likely that some
instances to be proxies and other instances to be materialized objects
just because maps get populated from strange places.
 
> And I don't see how your solution fixes this. (It doesn not, in fact,
seem
> fixable.)
> 
> fooWhichDoesntOverrideEquals.equals(fooProxy)
> 
> is ALWAYS going to return false, no matter what we do.....

There are two separate issues:

1) Hibernate only tries to optimize materializing proxies during
equals() for the case of reference equality, which is really not all
that useful.
2) It breaks when trying to do so.

#2 is easy to fix, and yes it means that proxies will be inequal with
their materialized version.  For that matter, different materialized
instances will be inequal.  If somebody doesn't override equals(),
that's what they're asking for.

However, #1 is the problem I want to address.  A more useful
optimization that hibernate can perform is to skip initializing proxies
during equals() when equals/hashCode follows identity:

public int hashCode() { return this.getId().hashCode(); }
public boolean equals(Object o) { return
this.getId().equals(((Entity)o).getId()); }

I suspect this is very, very common, and there is no reason to
materialize proxies in either case.  But since entities _could_ be
implemented with other equals/hashCode conventions, I figured this
optimization should be an option in the config file.

Make sense?

Jeff Schnitzer
[EMAIL PROTECTED]


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to