问题描述
我正在将运行Hibernate 3的应用程序迁移到Hibernate 5.
I am migrating an application running with Hibernate 3 to Hibernate 5.
我有一个奇怪的错误:
我们正在使用*.hbm.xml
映射文件,并且一切正常,直到我更改了Hibernate版本.我的意思是我们使用ID列和DB序列生成器进行了非常简单的映射,但是Hibernate仍然无法选择正确的配置.
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>
推荐答案
我开始研究Hibernate代码,发现不赞成使用SequenceGenerator
,而新版本使用的是SequenceStyleGenerator
.当我注意到在新版本中,告诉哪个序列名称的属性从sequence
更改为sequence_name
时,我感到非常困惑.所以最后,当我改变时:
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>
收件人:
<param name="sequence_name">my_class_seq</param>
一切正常.
这篇关于将Hibernate 3迁移到5:不存在hibernate_sequence关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!