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: Usertype.equals(obj x, obj y) contract re nulls
PostPosted: Mon Dec 06, 2004 6:04 pm 
Newbie

Joined: Thu Dec 02, 2004 7:24 pm
Posts: 3
In short, my question is...

Should UserType.equals(Object x, Object y) return true if both x and y are null?


More thoughts...

In Hibernate version 2.1.6 the javadoc for UserType.equals(Object, Object) doesn't address the contract if both arguments are null.
Code:
   /**
    * Compare two instances of the class mapped by this type for persistence "equality".
    * Equality of the persistent state.
    *
    * @param x
    * @param y
    * @return boolean
    */


What does "persistence equality" mean? If it means consistent with sql then the posts I've seen on this form that recommend an implementation like this
Code:
   public boolean equals(Object x, Object y) throws HibernateException {
        if (x == y) {
            return true;
        }
        if (x == null || y == null) {
            return false;
        }
        return x.equals(y); 
}


are not correct (select * from foo where null = null; never returns a row).
But I doubt that is what is meant. Can someone clarify this phrase, please?

Finally, assuming that two nulls should evaluate to true, may I suggest the following as more readable to those familiar with the Object.equals(Object) contract...
Code:
   public boolean equals(Object x, Object y) throws HibernateException {
        if (x == null) {
            return y == null;
        }
        return x.equals(y); 
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 6:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, it is assumed that null.equals(null).


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.