In Hibernate 6.0, hbm.xml multiple column has been disallowed, how to migrate them then?

335 Views Asked by At

Reading the migration path from Hibernate version 6.0, they disallowed the multiple column possibility, as stated in https://github.com/hibernate/hibernate-orm/blob/6.0/migration-guide.adoc#hbm-xml-multiple-column-now-disallowed

The issue I have (opened a ticket in https://hibernate.atlassian.net/browse/HHH-16232) is that I used this in Hibernate 5 to map an entity on 2 columns.

  • eventBody: contains the serialized representation of the event

  • typeName: contains the type name for the serializer to work

    public class StoredEvent {
        private DomainEvent event; // its an interface
        private long eventId;
        private Instant occurredOn;
        private String typeName;
    }
    

The mapping was working well in Hibernate 5 and I used a CompositeUserType to make this work (https://github.com/itsmoonrack/hibernate-test-case-templates/blob/main/orm/hibernate-orm-5/src/main/java/port/adapter/persistence/hibernate/DomainEventUserType.java):

<hibernate-mapping default-access="field" default-cascade="all">
<class name="event.StoredEvent" table="stored_event" lazy="true">
    <id name="eventId" type="long" column="event_id" unsaved-value="-1">
        <generator class="identity" />
    </id>
    <property name="event" type="port.adapter.persistence.hibernate.DomainEventUserType">
        <column name="event_body"/>
        <column name="type_name"/>
    </property>
    <property name="typeName" column="type_name" insert="false" update="false"/>
    <property name="occurredOn" column="occurred_on"/>
</class>
</hibernate-mapping>

I tried to migrate this to a new formal component but without succeeding, in my repository there is 3 use cases:

  • hibernate-orm-5/ORMUnitTestCase which does work as expected
  • hibernate-orm-6/ORMUnitTestCase which yield Could not locate field name [eventBody] on class [domain.model.DomainEvent]
  • hibernate-orm-6/ORMUnitTestCaseThatMayWork with the component approach but yields Could not determine recommended JdbcType for domain.model.DomainEvent

There is a full working reproducible case at: https://github.com/itsmoonrack/hibernate-test-case-templates/tree/main/orm

I have no idea how to migrate this and Hibernate team provide no sample of it. I am currently stuck and I even don't know if its a bug, or a feature request. I am looking for support and eventually will submit to the team the missing documentation to help people who encounter this case to have a migration path.

0

There are 0 best solutions below