0

I have an entity, let's say an item which uses a Lombok annotation @EqualsAndHashCode(callSuper = true) which autogenerates equals() and hashCode() methods. The entities are put inside a HashSet collection.

The problem is that when I am getting the collection from the DB (Spring JPARepository with Hibernate) PersistentSet proxy with my items in HashSet and when I am using the Lombok @EqualsAndHashCode the method persistentSet.contains(object) returns false. When my hashCode() returns 1 or other value but without the Lombok auto-generated methods, it works fine -> persistentSet.contains(object) returns true. What else the Lombok autogenerated hashCode() also seems fine because it returns the constant value for the given object within session. So I am lost.

Maybe someone has an idea what may we wrong here !?

Versions:
Hibernate: 5.3.9.Final
Lombok: 1.18.10
database: MySQL
Spring: 5.1.9.RELEASE

Michael Piefel
  • 18,660
  • 9
  • 81
  • 112
PrzemyslawP
  • 190
  • 1
  • 13
  • I think we need some (maybe simplified) code here... – Jan Rieke Nov 04 '19 at 16:52
  • I don't know what pieces of code put here because everything looks fine and there is nothing special in my code. Just a class with an equals/hascode created(1)/autogenerated(2) methods. – PrzemyslawP Nov 05 '19 at 09:14

1 Answers1

0

I have found a reason. One of the object properties had had a @PostLoad annotation. When invoking "persistentSet".contains(object) a hascode must be calculated before an initialization of the @PostLoad annotated properties.

PrzemyslawP
  • 190
  • 1
  • 13