-->
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.  [ 3 posts ] 
Author Message
 Post subject: deepCopy() while implementing UserType
PostPosted: Fri May 13, 2005 12:13 pm 
Newbie

Joined: Sun Nov 09, 2003 12:34 pm
Posts: 15
Hi,

Hibernate gurantees that the JavaIdentity for the persistable objects in the same session is same. Relying on Java identity, the objects do not implement equals() and hashCode().

However, in case of UserTypes where deepCopy() returns a real deep copy instead of returning the same object back, Hibernate always marks that object as dirty. Our problem was resolved by returning the same object back in deepCopy()

Code:
    public Object deepCopy(Object value) {
      return value;
    }


My questions are:
- When to return the same object and when to return a copy? What are the implications of each?
- Do we need to implement hashCode() and equals() if we return copy of an object in deepCopy()?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Fix your implementation of UserType.equals(x, y)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 12:48 pm 
Newbie

Joined: Sun Nov 09, 2003 12:34 pm
Posts: 15
Hi,

I have your book, in that it mentions that
Quote:
In case of a Mutable type, it would return a copy of the argument to be used as a snapshot value. This method is also called when an instance of the type is written to or read from the second level cache.


Are you implying that If I return a copy from deepCopy(), then I have to implement the UserType.equals(x,y) based upon the values and NOT rely on Java Identity?

Currently, my equals looks like this
Code:
    public boolean equals(Object x, Object y) {
        return ObjectUtils.equals(x, y);
    }


Thanks,


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