Hi all,
I'm unit testing some classes and I've faced some problems with equals and hibernate. I read the topic (
http://forum.hibernate.org/viewtopic.ph ... &start=105) but didn't get it yet.
I have an artist class which has a List of biography class.
My equals method is pasted bellow:
Artist
Code:
public boolean equals( Object object )
{
Artist artist = (Artist)object;
return getName().equals( artist.getName() ) && getBiographies().equals( artist.getBiographies() );
}
Biography
Code:
public boolean equals( Object object )
{
Biography bio = (Biography)object;
return this.text.equals( bio.text );
}
Consider the following example. Given the objects:
Code:
Artist artist1 = new Artist( "Name" );
artist1.getBios().add( new Biography( "Biography" ) );
Artist artist2 = new Artist( "Name" );
artist2.getBios().add( new Biography( "Biography" ) );
The results are the following:
Code:
artist1.equals( artist2 ); // true, ok
artist2.equals( artist1 ); // true, ok
The problem is if I persist artist1 I have the following results:
Code:
MyDao.save( artist1 );
artist1.equals( artist2 ); // false, not ok.
artist2.equals( artist1 ); // true, ok
artist1 is equals artist2 considering my equals method, but my List<Biography>.equals returns false and Biography.equals is not even called.
It seems to me that it has something to do with hibernate proxy.
Any help is apreciated.
Code:
Code: