I have one BaseEntity which abstracts id and version property. this class also implements hashcode and equals based on PK (id) property.
BaseEntity{
Lo
This is mostly an effect of standard Java inheritance.
a1.getB().equals(b1) uses Object.equals() (except if you've overridden equals() in your class), which only returns true if a1.getB() and b1 are the same instance. I don't know what you've done exactly (your code formatting is broken), but it looks like you've loaded a again in a different session, so you get a new instance for a and a.getB(), and consequently Object.equals() returns false.
a1.getB().getId().equals(b1.getId()) uses Long.equals(), which returns true if the long values are the same (even for different instances of the Long object), and these values are obviously the same.