gpt4 book ai didi

java - hibernate : strategy=GenerationType value for oracle

转载 作者:行者123 更新时间:2023-12-01 18:29:58 24 4
gpt4 key购买 nike

我的实体类:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="APP_INSTANCE")
public class ApplicationEntity {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="INSTANCE_KEY")
private int INSTANCE_KEY;
//other code
}

我的表结构:

CREATE TABLE "APP_INSTANCE" 
("INSTANCE_KEY" NUMBER NOT NULL ENABLE,
"SYS_ID" VARCHAR2(255) ,
"NAME" VARCHAR2(255) ,
"ENV" VARCHAR2(50) ,
PRIMARY KEY ("APP_INSTANCE_KEY") ENABLE
)

我正在使用 Spring 3、Hibernate 4 和 oracle 数据库。运行我的应用程序时出现以下错误:

03:23:07,380 INFO  [STDOUT] Hibernate: insert into USER.APP_INSTANCE (SYS_ID, NAME, ENV) values (?, ?, ?)
03:23:08,271 INFO [STDOUT] WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1400, SQLState: 23000
03:23:08,271 INFO [STDOUT] ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ORA-01400: cannot insert NULL into ("USER"."APP_INSTANCE"."INSTANCE_KEY")
03:23:08,271 INFO [STDOUT] Exception in saving..
03:23:08,271 ERROR [STDERR] org.hibernate.exception.ConstraintViolationException: could not execute statement
03:23:08,271 ERROR [STDERR] at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:74)
03:23:08,271 ERROR [STDERR] at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
03:23:08,271 ERROR [STDERR] at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)

我也尝试过GenerationType.AUTO,但后来我得到了类似sequence not found的东西。

请帮忙。我知道该问题与 @GenerateValue 有关。请让我知道上面的表和 Oracle 数据库的值。

最佳答案

您可以使用GenericGenerator hibernate 类。

@Id
@GenericGenerator(name = "increment", strategy = "increment")
@GeneratedValue(generator = "increment")
private int INSTANCE_KEY;

关于java - hibernate : strategy=GenerationType value for oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24693015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com