@PrePersist (and @PreUpdate) do not work on @Embeddable when the entity having the @embedded is also annotated with @Inheritance(strategy = InheritanceType.JOINED)

Description

This is a follow up of the resolved bug that was fixed in 5.2.17 and was presented in the article
How to use @PrePersist and @PreUpdate on Embeddable with JPA and Hibernate

When the @Embeddable containing the @PrePersist is embedded in a entity that is the a parent entity in a relation with strategy JOINED then the @PrePersist fails to trigger and the columns are not updated

Environment

None

Activity

Show:
Christos
April 12, 2019, 2:02 PM

Similar to

The issue seems to be the following:
lets say we have the superclass A that has the @PrePresist annotation and a subclass B that extends the A,
Initially the @PrePersist annotation are scanned and are added in a Map . The key of the map is the class the @PrePersist annotation is found. So in our case it will be registered under the key "A"
When the entity B is going to be saved, the callbacks for this entity are executed, but there is no @PrePersist callback in the callbacks registry (the aforementioned map) under the key B.

So naively i guess that either in the annotation discovery we need also to register all the extending classes of A,
Or, during the persist of an entity we need to check if there is any @PrePersist callback registered for its parent

The relevant methods are :
CallbackBuilderLegacyImpl.buildCallbacksForEmbeddable(..)
AbstractSaveEventListener.saveWithGeneratedId(..)

Assignee

Unassigned

Reporter

Christos

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure