We experienced some problems implementing our own equals() methods. So we accidentally forgot to compare a relationship field in an entity and got some nasty OpenJPA errors like that:
/org.apache.openjpa.persistence.ArgumentException: Encountered new object in persistent field "MyEntity.myField" during attach. However, this field does not allow cascade attach. Set the cascade attribute for this field to CascadeType.MERGE or CascadeType.ALL (JPA annotations) or "merge" or "all" (JPA orm.xml). You cannot attach a reference to a new object without cascading./ We then deleted all equals() methods in our entities and DTOs and the error was gone. Well, we could have fixed the method instead. ;-) But now we wonder about the need of equals(). Apparently OpenJPA does not need equals() to check for new or changed entities. So does it have any advantages to override equals() in JPA entities? Would you recommend overriding equals() or leave it up to OpenJPA's internal checks? Are there any fundamental reasons to use equals()? What are your experiences and best practices? Thanks a lot for your input! -- View this message in context: http://openjpa.208410.n2.nabble.com/Best-practice-Overriding-equals-in-entities-tp6672154p6672154.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
