jpa - "HIBERNATE_SEQUENCE" not found
问题描述
I have two tables EmployeeGroup table and EmpplyeeDetails Table. EmployeeGroupTable has primary key groupid which should be generated from databse sequence GroupIdGenerator. EmployeeDetails have two primary keys as groupid and employeeid. Groupid should be same as of the previous table and employeeid should also have incremented value like 1,2,3. These values in both table should insert in one transaction. Can you help me with correct mapping?
I already tried with different combination of Generated value and Sequence generator but not able to save the data into table.
@Entity
@Table(name="EMPLOYEE_GROUP")
public class EmployeeGroup {
@Column(name = "GROUP_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"groupid-gen")
@Id
@NotNull
@SequenceGenerator(name = "groupid-gen", sequenceName =
"GROUIP_ID_GENERATOR" )
private long groupId;
@OneToMany(mappedBy = "employeeDetail")
private List<EmployeeDetail> employeeDetails;
}
@Entity
@Table(name = "EMPLOYEE_DETAIL")
@IdClass(EmployeeID.class)
public class EmployeeDetail {
@ManyToOne
@JoinColumn(name = "GROUP_ID", insertable=false , updatable=false)
private EmployeeGroup employeeGroup;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"groupid-gen")
@SequenceGenerator(name = "groupid-gen", sequenceName =
"GROUIP_ID_GENERATOR" )
@Column(name = "GROUP_ID")
@Nonnull
private Long groupId;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Nonnull
@Column(name = "EMPLOYEE_ID")
private Long employeeId;
}
public class EmployeeId{
private Long groupId;
private Long employeeId;
public EmployeeId(final Long groupId, final Long employeeId) {
this.groupId = groupId;
this.employeeId = employeeId;
}
public EmployeeId() {
}
}
Expected result is both table should have proper values like.
Table EmployeeGroup
GroupID
1
2
Table EmployeeDetail
GroupId EmployeeId
1 1
1 2
1 3
2 1
2 2
I am getting error as ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Sequence "HIBERNATE_SEQUENCE" not found; SQL statement: call next value for hibernate_sequence [90036-197] org.springframework.orm.jpa.JpaSystemException: could not prepare statement; nested exception is org.hibernate.exception.GenericJDBCException: could not prepare statement
解决方案
您正在混合 Id 生成器策略:
在课堂EmployeeDetail
上,您有一个 Oracle 序列,groupId
但GenerationType.AUTO
employeeId
这GenerationType.AUTO
会导致问题。
要么你必须在那里使用 Oracle 序列,要么@GeneratedValue
如果这个 id 来自其他任何地方,你必须删除。
推荐阅读
- html - ReactStrap 分页元素超出可用宽度
- reactjs - 调用材质 ui 对话框
- python - 使用 Django 使用 AJAX 在 Bootstrap Modal 中动态加载内容
- javascript - vue.js 项目中没有任何渲染
- xamarin.forms - 在 xamarin 表单中,当从后台打开应用程序但应用程序状态在后台被操作系统杀死时,在 app.cs 中调用了哪个覆盖方法
- android - 找不到 com.android.tools.build:gradle:4.0.0
- c++ - 关于以非常规方式实现邻接矩阵的问题
- java - 自定义系统类未在命令行中编译
- mysql - SQL 数据库中的 ORDER BY 语句语法错误
- android-emulator - 在模拟器上测试三星智能电视的应用程序