high-performance-java-persistence icon indicating copy to clipboard operation
high-performance-java-persistence copied to clipboard

Add tests for inherited entity reference equality

Open ivan-zaitsev opened this issue 3 years ago • 1 comments

Hi, Vlad. I wrote some tests for equality when we have inheritance.


Test class - InheritedEntityReferenceEqualityTest

Test method - testInheritedEntityReferenceEqualityInOnTransaction

When we try to persist entity in one transaction and after it use getReference everything works as expected.

Test method - testInheritedEntityReferenceEqualityInDifferentTransactions

In this test case we separate entity persist from getReference, and after it the instanceof or o.getClass() check for inherited entity does`t work.


Example: postProxy.hashCode() == post.hashCode(); // = true postProxy.getClass() == post.getClass(); // = false postProxy instanceof Post // = false post instanceof Post // = true postProxy.equals(post); // = true post.equals(postProxy); // = false


Possible solutions to resolve this problem: use Hibernate.getClass(o) instead of !(o instanceof Topic) or getClass() != o.getClass() in equals method.

ivan-zaitsev avatar Nov 09 '21 21:11 ivan-zaitsev

Cool. I'll have to investigate it when I have some time. Currently, I'm very busy launching a new product.

vladmihalcea avatar Nov 10 '21 07:11 vladmihalcea