-->
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.  [ 4 posts ] 
Author Message
 Post subject: Equals and casting problem with proxy
PostPosted: Thu Jan 11, 2007 6:03 am 
Newbie

Joined: Fri Dec 15, 2006 6:39 am
Posts: 3
Hibernate version: 3.2.1

Hello,

Here is an excerpt of my equal method:

Code:
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
//        FIXME: need to equal the classes
//        if (getClass() != obj.getClass()) {
//            return false;
//        }
[code]//        if (getClass().isAssignableFrom(obj.getClass())) {
//            return false;
//        }[/code]

//More business comparison here...


My problem is that following return always false :
Code:
//        if (getClass() != obj.getClass()) {
//            return false;
//        }

and
Code:
//        if (getClass().isAssignableFrom(obj.getClass())) {
//            return false;
//        }

which poses problems in the future.

This problem doesn't happen all the time. Only when using a proxy and a transient object.
e.g. myPersistentObject.equals(myTransientObject) or vice versa.

The casting do work, but it's unsafe as long I haven't checked the class.
I'm using the cglib bytecode.

How can I check that my method argument is of the same class as the class on which the equals is called?

Thx in advance for any input.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 1:25 pm 
Newbie

Joined: Tue Dec 19, 2006 11:05 am
Posts: 11
You may consider to call Hibernate.getClass(obj) for the object...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 1:27 pm 
Newbie

Joined: Tue Dec 19, 2006 11:05 am
Posts: 11
Note that this would initialize the proxy...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 2:11 am 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
Wiemer wrote:
Note that this would initialize the proxy...


http://www.hibernate.org/hib_docs/v3/api/org/hibernate/proxy/HibernateProxyHelper.html#getClassWithoutInitializingProxy(java.lang.Object)

doesnt intialize the proxy..

_________________
Don't forget to rate


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