使用 Oracle 序列时 Hibernate 不生成标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1729723/
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
Hibernate does not generate identifier when using Oracle sequence
提问by Arthur Ronald
I have the following mapping
我有以下映射
@Entity
@SequenceGenerator(name="sacpSequenceGenerator", sequenceName="SACP_SEQ")
public class Sacp {
private Integer id;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sacpSequenceGenerator")
public Integer getId() {
return this.id;
}
// other setter's and getter's
}
SACP Table is mapped according to
SACP表根据
ID NUT NULL NUMBER(4)
When i try to save a Sacp instance, Hibernate complains
当我尝试保存 Sacp 实例时,Hibernate 会抱怨
ORA-01438: Value larger than specified precision allows for this column
ORA-01438: 大于指定精度的值允许此列
Even when using a Long instead of Integer, same error is thrown
即使使用 Long 而不是 Integer,也会抛出同样的错误
What should i do to fix it ?
我该怎么做才能修复它?
采纳答案by Arthur Ronald
I have found this
我找到了这个
SEQ_GEN defines a sequence generator using a sequence named my_sequence. The allocation size used for this sequence based hilo algorithm is 20. Note that this version of Hibernate Annotations does not handle initialValue in the sequence generator. The default allocation size is 50, so if you want to use a sequence and pickup the value each time, you must set the allocation size to 1.
SEQ_GEN 使用名为 my_sequence 的序列定义了一个序列生成器。用于此基于序列的 hilo 算法的分配大小为 20。请注意,此版本的 Hibernate Annotations 不处理序列生成器中的 initialValue。默认分配大小为 50,因此如果您想使用序列并每次取值,则必须将分配大小设置为 1。
And now it works fine
现在它工作正常