Unable to pass the listeners (callback) to HBM


I am in the process of defining the mapping of an object via an hbm.xml file because inheritance is not working correctly and is preventing the use of standard annotations.

I have almost managed to do everything, but I am unable to provide the definition for the @EntityListeners.

I have the impression that CallbackDefinition on the PersistentClass is only populated with annotations. I even tried adding it by default, but it doesn’t work for HBM entities.

Basically, I have the impression that for HBM, there is nothing to transmit the listeners, but that seems strange to me. Am I missing something?

I have debugged quite a bit before asking you.

Thank you very much.

Guide events-default-listener


Please try to create a reproducer with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) and if you are able to reproduce the issue, create a bug ticket in our issue tracker(https://hibernate.atlassian.net) and attach that reproducer.

1 Like

Actually, I can’t run a test to demonstrate the case because I don’t have the ability to specify a callback to a mapping definition via HBM precisely.

I can show you the HBM mapping.

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping  package="com.hermes.ref.acteur.businessobject" >

    <class  name="ActeurInterne" table="TACTEURINTERNE">

        <discriminator column="ROLE" length="80"/>

        <id name="idHibernate">
            <column name="ID" length="25"/>
            <generator class="com.efluid.hibernate.core.EfluidGeneratorIdentifiant"/>

        <property name="acteurCreation" length="50"/>
        <property name="acteurModification" length="50"/>
        <property name="acteurSuppression" length="50"/>
        <property name="dateCreation"/>
        <property name="dateModification"/>
        <property name="dateSuppression"/>
        <property name="etatObjet">
            <column name="ETATOBJET" sql-type="number(1,0)"/>
        <property name="agence" length="25"/>

        <subclass name="EntiteAdministrative"
            <property name="categorieEntite" length="80"/>

        <subclass name="Agent" discriminator-value="com.hermes.ref.acteur.businessobject.Agent">



But for now, I’ve found this solution by manually intervening on the metadata.

You can alter some static variable i.e. static boolean called; in your listener and check that the flag was set in an assertion to verify that a listener was called.

But I mean I have no XML tag to pass the listener in question.
It’s as if @EntityListeners doesn’t exist for annotation-based mapping.

You can specify the listener in a JPA orm.xml: Hibernate ORM User Guide
This is the <entity-mappings/> file you have posted a picture of.

Ah, indeed, sorry. I was still focused on the HMB file.
I’ll do that as soon as possible. Thank you.

Note that for configuration via XML file, it would be possible to specify default listeners for all entities (which I will test), and it’s not possible to define a specific one for a particular entity.

With hbm.xml it’s not possible, but with pure orm.xml you can define a listener per entity/mapped-superclass. Who knows, maybe it even works in combination with hbm.xml. I haven’t tried though.

I just noticed that the use of <hibernate-mapping> is deprecated (hbm.xml).
It suggests using orm.xml or mapping.xml or enable hibernate.transform_hbm_xml.
Which do you think is better to use?

10:58:33,447|WARN |{}|orm.deprecation|main|HHH90000028: Support for <hibernate-mappings/> is deprecated [INPUT_STREAM : D:\java\workspaces\developpement_dev\efluid\app\target\classes\com\hermes\ref\acteur\businessobject\ActeurInterne.hbm.xml]; migrate to orm.xml or mapping.xml, or enable hibernate.transform_hbm_xml.enabled for on the fly transformation

The best way IMO is to use annotations, but if you must use XML, you should use orm.xml since hbm.xml will probably be removed in ORM 7, which will be released later this year.

1 Like

I just understood:

  • hbm.xml is a separate complete definition from the mapping but it will disappear
  • orm.xml is simply the completion of annotations by text file

In my case, the issue is that I want to avoid keeping an inheritance from a problematic parent class, so I am forced to use hbm.xml.

It’s worth noting that this is temporary, just while we make the necessary changes to the incorrect model. This will resolve the situation for the next 6 to 8 months.


My specific case

Given that HMB is going to be deprecated, is it worth it for me to create a reproduction test and a JIRA ticket?

Probably not. You should rather try to port this over to orm.xml or annotations.