Search code examples
javahibernate

Migrating Hibernate 3 to 5: relation hibernate_sequence does not exist


I am migrating an application running with Hibernate 3 to Hibernate 5.

I have a strange error:

ERROR: relation hibernate_sequence does not exist

We are using *.hbm.xml mapping files and everything was working fine until I changed the Hibernate version. I mean we have a pretty straight forward mapping with ID column and DB sequence generator and still Hibernate wasn't able to pick the correct config.

<hibernate-mapping>
    <class name="com.boyan.MyClass" table="my_class">
       <id name="id" type="long">
            <column name="id" />
            <generator class="sequence">
               <param name="sequence">my_class_seq</param>
            </generator>
        </id>
...
    </class>
</hibernate-mapping>

Solution

  • I started digging in the Hibernate code and saw that SequenceGenerator is deprecated and the new versions use SequenceStyleGenerator. I was very confused when I noticed that in the new version the property telling which is the sequence name is changed from sequence to sequence_name. So finally when I changed:

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

    to:

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

    everything worked.