My apologies if this has been covered, but I couldn't find it anywhere in the list or the forums. My concern is that hbm2java generates an equals() method that looks something like:
public boolean equals(Object other) { if ( !(other instanceof MyObject) ) return false; MyObject castOther = (MyObject) other; return new EqualsBuilder() .append(this.getId(), castOther.getId()) .isEquals(); }
Which works fine when comparing two non-transient objects, or a transient and a non-transient (where transient means getId() == null). However, this equals considers all transient objects to be equal which causes serious problems when doing things like list.remove(myObject) when you've got all transients in the list (in fact it will always remove the first element). I have modified the equals to be something like:
public boolean equals(Object other) { if ( !(other instanceof MyObject) ) return false; MyObject castOther = (MyObject) other; if (this.getId() == null && castOther.getId() == null) { return super.equals(other); } else { return new EqualsBuilder() .append(this.getId(), castOther.getId()) .isEquals(); } }
So when two transients are compared it uses the standard Java object compare, otherwise it uses the ids as before.
Does this make sense to people or am I missing something?
Thanks.
Matt
------------------------------------------------------- This SF.Net email sponsored by: ApacheCon 2003, 16-19 November in Las Vegas. Learn firsthand the latest developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! http://www.apachecon.com/ _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel