2

I have a question that is similar to this question but in a slightly different way that makes all the difference.

My problem is that I'm in the process of migrating a project portfolio from Java 8/Hibernate 4.x stack to a Java 11/Hibernate 5.4 stack.

In the second case, I get this error as soon as the application tries to save an object:

org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist

The answers to the other question I mentioned above provided some insight but I'm still not understanding why that error occurs: all of our entities have been using each his own sequence and the sequence is clearly specified in the corresponding hbm.xml. Here is one such mapping file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
    <class name="…" table="data_receiving">
        <id name="systemId" column="system_id">
            <generator class="sequence">
                <param name="sequence">system_id_seq</param>
            </generator>
        </id>
        <property name="source" column="source" />
        …
    </class>
</hibernate-mapping>

It looks like the specification of the sequence is being ignored. I've looked up some documentation of the legacy Hibernate mapping with XML, but I could not find anything related to Hibernate 5, which reportedly still supports such mappings.

A solution could have been to migrate altogether to annotations, but the portfolio contains a dozen of applications which have scores of tables and a total number (in one application) of columns over 1200. The task is simply impractical, all the more since some applications are being rewritten from scratch as microservices.

My question is whether the specification of a sequence-generated identifier that I've is still supported?

1 Answer 1

5

I have had to delve into the source code of Hibernate to find that one out: parameter sequence has been renamed to sequence_name.

<param name="sequence">system_id_seq</param>

must now be

<param name="sequence_name">system_id_seq</param>

This makes it necessary to update all hbm.xml files, which I did using a find and replace in Eclipse.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for sharing this. Do you know how to call a sequence ? I'm assuming you created a sequence by name system_id_seq and have been calling it in Legacy Hibernate? I'm using Legacy Hibernate as well.
Calling a sequence from code is quite tangent to the question I was asking and answering here. You will have to search for that specific information as it seems to me the answer will depend on the programming language and technical stack that you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.