'Hibernate 5.6 event listeners are not working

I have a project that was recently upgraded from Hibernate 5.3 to Hibernate 5.6 We are using Spring Boot and Spring Data too.

Before upgrading, the event listeners were working just fine, but now they are not triggered or even instantiated.

BaseEntityEventListener.hml.xml

<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
                     http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd"
                     version="2.1">

    <persistence-unit-metadata>
        <persistence-unit-defaults>
            <entity-listeners>
                <entity-listener class="path.to.class.BaseEntityEventListener">
                    <pre-persist method-name="onPrePersist"/>
                    <pre-update method-name="onPreUpdate"/>
                </entity-listener>
            </entity-listeners>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
</entity-mappings>


BaseEntityEventListener.java

public class BaseEntityEventListener {

    
    public void onPrePersist(BaseEntity entity) {
        entity.create();
    }

    public void onPreUpdate(BaseEntity entity) {
        entity.update();
    }
}

According to Hibernate documentation, everything is fine.

How to enable the event listeners again?

Also:

  • I tried adding the listeners as annotations and won't work either.
  • The entities are also mapped as hbm.xml and are working fine.
  • The xml file is added in application.yaml


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source