Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating Hibernate 3 to 5: relation hibernate_sequence does not exist

Tags:

java

hibernate

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>
like image 240
Boyan Avatar asked Feb 05 '16 17:02

Boyan


2 Answers

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.

like image 190
Boyan Avatar answered Oct 06 '22 00:10

Boyan


I bumped in to the same problem and I was using annotations. Solution was the accepted answer JPA GenerationType.AUTO not considering column with auto increment. If using annotations following should be used.

@GenericGenerator(name = "my_seq", strategy = "native", parameters = {
    @Parameter(name = "sequence_name", value = "mydb_seq")
})
like image 37
Dev Blanked Avatar answered Oct 06 '22 00:10

Dev Blanked