休眠和Oracle序列 [英] Hibernate and Oracle Sequence
问题描述
我有一个Oracle序列和Hibernate的问题。我使用这段代码来获取带有hibernate的Oracle序列
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator =student_id_seq)
@SequenceGenerator(name =student_id_seq,sequenceName =Student_seq)
@Column(name =StudentID)
public Long getStudentId(){
返回this.studentId;
}
public void setStudentId(Long studentId){
this.studentId = studentId;
}
但是当我向表中插入新值时,生成的值不正确。例如:
当我在数据库中有两个记录时,id为2和3,当我插入新的记录时,它的id不是4但是是25.我不知道该怎么做。
您应该将 allocationSize
设置为 1 $ c $
$ $ p $ code $ @ student_id_seq,
sequenceName =Student_seq,
allocationSize = 1)
您可以阅读文档 SequenceGenerator文档
I have a problem with Oracle sequence and Hibernate. I used this code to get Oracle Sequence with hibernate
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "student_id_seq")
@SequenceGenerator(name = "student_id_seq", sequenceName = "Student_seq")
@Column(name = "StudentID")
public Long getStudentId() {
return this.studentId;
}
public void setStudentId(Long studentId) {
this.studentId = studentId;
}
but when i insert a new value to the table, the generated value is incorrect. For example: when I had two records in database with id 2 and 3, and when I inserted new one, it's id was not 4 but 25. I have no idea what to do with it.
You should set allocationSize
to 1
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "student_id_seq")
@SequenceGenerator(name = "student_id_seq",
sequenceName = "Student_seq",
allocationSize = 1)
You can read more in documentation SequenceGenerator doc
这篇关于休眠和Oracle序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!