无法使用 Ebean 使用 GENERATED IDENTITY 主键创建记录
Unable to create record with GENERATED IDENTITY primary key using Ebean
我在 Oracle Database 12c 中有一个 table,使用以下 DDL 创建:
create table customer (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name VARCHAR(100)
);
我正在尝试使用 Ebean.save 方法向此 table 插入一行,模型定义如下:
@Entity
@Table(name = "customer")
public class Customer {
@Id
Integer id;
....
用于插入行的代码如下:
Customer customer = new Customer();
customer.setName(name);
Ebean.save(customer);
失败并显示以下堆栈跟踪:
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:446)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1054)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:623)
....
Caused by: Error : 2289, Position : 7, Sql = select
customer_seq.nextval, a from (select level as a FROM dual CONNECT BY level <= 20), OriginalSql = select customer_seq.nextval, a from (select level as a FROM dual CONNECT BY level <= 20), Error Msg = ORA-02289: sequence does not exist
从错误中,我了解到 Ebean 正在尝试对标识列使用 Sequence
策略,但失败了。我试过如下设置 Identity
策略但没有成功,可能是因为 Ebean 正在对 Oracle DB 使用 Sequence
策略,如 here.
所述
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id;
有没有办法在 Oracle 12c table 中使用 Ebean 定义的自动生成的标识列保存一行?我设置 IDENTITY
策略是否正确?
我在 Oracle Database 12c 中有一个 table,使用以下 DDL 创建:
create table customer (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name VARCHAR(100)
);
我正在尝试使用 Ebean.save 方法向此 table 插入一行,模型定义如下:
@Entity
@Table(name = "customer")
public class Customer {
@Id
Integer id;
....
用于插入行的代码如下:
Customer customer = new Customer();
customer.setName(name);
Ebean.save(customer);
失败并显示以下堆栈跟踪:
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:446)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1054)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:623)
....
Caused by: Error : 2289, Position : 7, Sql = select
customer_seq.nextval, a from (select level as a FROM dual CONNECT BY level <= 20), OriginalSql = select customer_seq.nextval, a from (select level as a FROM dual CONNECT BY level <= 20), Error Msg = ORA-02289: sequence does not exist
从错误中,我了解到 Ebean 正在尝试对标识列使用 Sequence
策略,但失败了。我试过如下设置 Identity
策略但没有成功,可能是因为 Ebean 正在对 Oracle DB 使用 Sequence
策略,如 here.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id;
有没有办法在 Oracle 12c table 中使用 Ebean 定义的自动生成的标识列保存一行?我设置 IDENTITY
策略是否正确?