high-performance-java-persistence
high-performance-java-persistence copied to clipboard
Add tests for inherited entity reference equality
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.
Cool. I'll have to investigate it when I have some time. Currently, I'm very busy launching a new product.