本文介绍了休眠和Oracle序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Oracle序列和Hibernate的问题。我使用这段代码来获取带有hibernate的Oracle序列

  

您应该将 allocationSize 设置为 1
$ $ p $ code $ @ student_id_seq,
sequenceName =Student_seq,
allocationSize = 1)

您可以阅读文档


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序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:51