Hibernate migration 3 through 5: hibernate_sequence relationship does not exist

I am migrating an application that works with Hibernate 3 to Hibernate 5.

I have a strange error:

ERROR: hibernate_sequence relationship does not exist

We use the *.hbm.xml mapping files and everything works fine until I change the version of Hibernate. I mean, we have a pretty direct comparison with the column id and the database sequence generator, and still Hibernate was unable to select the correct configuration.

 <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> 
+5
source share
2 answers

I started digging in Hibernate code and saw that the SequenceGenerator out of date and newer versions are using the SequenceStyleGenerator . I was very confused when I noticed that in the new version, the property that defines the name of a sequence changes from sequence to sequence_name . So when I changed:

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

in

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

everything worked.

+10
source

I ran into the same problem and I used annotations. The decision was made by JPA GenerationType.AUTO's answer , not counting the auto-increment column . If you need to use the following notes, follow these steps:

 @GenericGenerator(name = "my_seq", strategy = "native", parameters = { @Parameter(name = "sequence_name", value = "mydb_seq") }) 
+1
source

Source: https://habr.com/ru/post/1242390/


All Articles