Java org.hibernate.exception.SQLGrammarException: 无法获得下一个序列值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18895168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.hibernate.exception.SQLGrammarException: could not get next sequence value
提问by user2488578
Am using Hibernate 3.6
我正在使用 Hibernate 3.6
Below is Employee
class code.
下面是Employee
类代码。
public class Employee {
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
Below is Employee.hbm.xml
file,
下面是Employee.hbm.xml
文件,
<class name="com.testing.hibernate.Employee" table="HIB_EMPLOYEE">
<meta attribute="class-description">
This class contains the Employee details.
</meta>
<id name="id" type="int" column="id">
<generator class="sequence"></generator>
</id>
<property name="firstName" column="first_name" type="string"></property>
<property name="lastName" column="last_name" type="string"></property>
<property name="salary" column="salary" type="int"></property>
</class>
I have created sequence in Database. Below SS for reference. How can I overcome the exception that am getting?
我在数据库中创建了序列。下面SS供参考。我怎样才能克服出现的异常?
采纳答案by Abhijith Nagarajan
You have to give the reference of the sequence to hibernate.
您必须提供序列的参考以进行休眠。
<generator class="sequence">
<param name="sequence">SEQUENCE_NAME</param>
</generator>
回答by Gon?alo
What annotation can i use to do this?
我可以使用什么注释来做到这一点?
i've tried
我试过了
@GeneratedValue(strategy=GenerationType.SEQUENCE , generator = <SEQUENCE_NAME>")
without any success
@GeneratedValue(strategy=GenerationType.SEQUENCE , generator = <SEQUENCE_NAME>")
没有任何成功
edit:
编辑:
it seams that the generator have to also be created
它接缝还必须创建生成器
@SequenceGenerator(name="<GEN_NAME>", sequenceName="<SEQUENCE_NAME>")
@SequenceGenerator(name="<GEN_NAME>", sequenceName="<SEQUENCE_NAME>")