Hello, I am having a very weird problem at the moment using hibernate’s interceptor and trying to intercept a change in a collection for an entity. It seems that when onFlushDirty is called that both previous and current state contain the same reference to the PersistentCollection that has been changed. If i inspect the snapshot contained in the collection it is ineed the old state, also isDirty returns true. Despite that the reference in both current & previous state are the same - contains the current state of the collection. I am linking a very similar / issue that has already been discussed and reported. Any help would be appreciated !! - Related problem -
https://hibernate.atlassian.net/browse/HHH-2975
// The Code below is completely isolated in a test environment.
@Entity
@Table(name = "complex_details")
public class ComplexDetailsTestEntity extends CoreEntity {
@Version
@Column(name = "version")
private Long version;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "complex", referencedColumnName = "id")
private Set<RandomDetailsTestEntity> ownedList = new HashSet<>();
}
// Relevant code demonstrating how i persist the entry in the collection
complex.getOwnedList().add(new RandomDetailsTestEntity().setRandom("random-details-1").setComplex(complex));
complex.getOwnedList().add(new RandomDetailsTestEntity().setRandom("random-details-2").setComplex(complex));
complex = complexDetailsEntityRepository.save(complex);
// This is the point i am intercepting, the Changed Parent Entity enters the interceptor through
// onFlushDirty, but both previous and current states (inspected from Object[] currentState, Object[]
// previousState) of the ownedList are the exact same object (PersistentCollection containing 0 entries,
// same reference / address). When i inspect the ownedList the snapshot is ineed containing the old
// state (the previously inserted 2 entries)
complex.getOwnedList().clear();
complexDetailsEntityRepository.save(complex);
Note that the code does compile & run, without throwing any exceptions, the database is getting properly updated, created entries are created, then deleted upon clearing the list, everything works as expected, except the problem with the collection’s state mentioned above. The Hibernate version i am using is 5.3.13.Final with spring 2.1.10.RELEASE