Two entities that have no identifier cannot be assumed to be equal

Description

Two entities that have no identifier cannot be assumed to be equal!!!!!!

Currently the following code will add just one Child: (assuming you have cascade save)

Parent p1 = new Parent("P1");
Child c1 = new Child("C1");
Child c2 = new Child("C1");
//Both c1 and c2 have no identifier
p1.getChildren().add(c1);
p1.getChildren().add(c2);
//(p1.getChildren().size == 1) is true as c1.equals(c2)
session.save(p1); //only one child saved

In the body of equals method there is:

#else
if (this.$identifier.name == null ? that.$identifier.name != null : !this.${identifier.name}.equals(that.$identifier.name))
{
return false;
}
#end
#end
return true;
#end

there should be:

#else
if (this.$identifier.name == null || that.$identifier.name == null || !this.${identifier.name}.equals(that.$identifier.name))
{
return false;
}
#end
#end
return true;
#end

Environment

None

Status

Assignee

MichaelM

Reporter

Michal Bielecki

Labels

None

Fix versions

Affects versions

3.0-RC1

Priority

Major
Configure