5

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>
spongebob
  • 8,370
  • 15
  • 50
  • 83
Boyan
  • 589
  • 5
  • 19

2 Answers2

14

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.

spongebob
  • 8,370
  • 15
  • 50
  • 83
Boyan
  • 589
  • 5
  • 19
1

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")
})
Community
  • 1
  • 1
Dev Blanked
  • 8,555
  • 3
  • 26
  • 32