Joshua Bonn ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ce2c27... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMTFjMmVlYThl... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16602?atlOrigin=eyJpIjoiMTFjMm... ) HHH-16602 ( https://hibernate.atlassian.net/browse/HHH-16602?atlOrigin=eyJpIjoiMTFjMm... ) EntityUpdateAction for deleted Entity ( https://hibernate.atlassian.net/browse/HHH-16602?atlOrigin=eyJpIjoiMTFjMm... )
Issue Type: Bug Affects Versions: 6.2.2 Assignee: Unassigned Attachments: hibernate-orm-6.zip Components: hibernate-core Created: 15/May/2023 03:48 AM Environment: Eclipse Adoptium 17.0.2+8 Priority: Major Reporter: Joshua Bonn ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ce2c27... )
Reproducible with attached test case.
We have two entities in our domain model which are related similar to the TreeNode and ReferencedEntity classes.
@Entity
public static class TreeNode {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(optional = true)
@JoinColumn(name = "parent_id")
private TreeNode parent;
@OneToMany
private Set<ReferencedEntity> someSet = new HashSet<>();
}
@Entity
public static class ReferencedEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
TreeNodes have a reference to their parents and a set of references to some ReferencedEntities.
In our production code we have several custom validations that access the someSet property of TreeNode.
After upgrading to Hibernate 6.2.2.Final (from Version 5.6.14.Final) these validations failed when deleting TreeNode entities (through the deleteAll method of a CrudRepository). The stack trace was similar to the one generated by the attached test case:
java.lang.NullPointerException: Cannot invoke "org.hibernate.persister.collection.CollectionPersister.hasCache()" because "persister" is null
at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:131)
at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:59)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1697)
at org.hibernate.collection.spi.AbstractPersistentCollection.lambda$initialize$3(AbstractPersistentCollection.java:617)
at org.hibernate.collection.spi.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:265)
at org.hibernate.collection.spi.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:615)
at org.hibernate.collection.spi.AbstractPersistentCollection.read(AbstractPersistentCollection.java:136)
...
By debugging the (hibnerate) code we found that a UpdateEntityAction was generated on flush because the parent property was different. As far as we could see, this happened because parent was set to null in the DefaultDeleteEventListener using ForeignKeys.Nullifier.
The test case simulates the validation using a PreUpdateEventListener that accesses the someSet property.
( https://hibernate.atlassian.net/browse/HHH-16602#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16602#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:a5851ae )