每当应用程序启动时,我总是收到以下错误消息:
Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.SERMON_SESSION(ID)"; SQL statement:
INSERT INTO SERMON_SESSION (id, session_enum) VALUES ('1', 'SUN_MRN'), ('2', 'SUN_EVE'), ('3', 'TUE_BIB'), ('4', 'FRI_BIB'), ('5', 'WKD_CNF') [23505-197]
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:mem:erc;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.initialization-mode=embedded
spring.jpa.properties.hibernate.hbm2ddl.import_files=classpath://resources/data.sql
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.hbm2ddl.import_files_sql_extractor=org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor
logging.level.com.erc.api.*=DEBUG
logging.level.org.hibernate=OFF
logging.level.org.hibernate.SQL=INFO
logging.level.org.hibernate.type.descriptor.sql=INFO
logging.level.org.jaudiotagger=WARN
spring.servlet.multipart.max-file-size=60MB
spring.servlet.multipart.max-request-size=60MB
application.sermon_path=classpath://resources/files/sermons/}
@Table(name = "sermon_session", uniqueConstraints = @UniqueConstraint(columnNames = {"id", "sessionEnum"}))
@Entity
public class SermonSession {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false, nullable = false, unique = true)
private int id;
@Enumerated(EnumType.STRING)
@Column(unique = true)
private SessionEnum sessionEnum;
public SermonSession(String session) {
setSessionEnum(session);
}
public SermonSession() {
this.sessionEnum = null;
}
public String toString() {
return String.format("{ id: %d, session_enum: %s }", getId(), getSessionEnum());
}
String getSessionEnum() {
return this.sessionEnum.getSession();
}
private void setSessionEnum(String session) {
this.sessionEnum = SessionEnum.fromSession(session);
}
private int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
INSERT INTO SERMON_SESSION (id, session_enum)
VALUES ('1', 'SUN_MRN'),
('2', 'SUN_EVE'),
('3', 'TUE_BIB'),
('4', 'FRI_BIB'),
('5', 'WKD_CNF');
将data.sql更改为:
INSERT INTO SERMON_SESSION (session_enum)
VALUES ('SUN_MRN'),
('SUN_EVE'),
('TUE_BIB'),
('FRI_BIB'),
('WKD_CNF');
产生以下错误消息:
Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "UK_AA7KWY8HO9GLHF1VI4HDB61X8_INDEX_8 ON PUBLIC.SERMON_SESSION(SESSION_ENUM) VALUES ('SUN_MRN', 1)"; SQL statement:
INSERT INTO SERMON_SESSION (session_enum) VALUES ('SUN_MRN'), ('SUN_EVE'), ('TUE_BIB'), ('FRI_BIB'), ('WKD_CNF') [23505-197]
@generatedvalue(strategy=generationtype.identity)
将允许自动生成唯一ID,而不需要自己将其放在那里。
以下内容应该是绰绰有余的
DELETE FROM SERMON_SESSION;
INSERT INTO SERMON_SESSION (session_enum)
VALUES ('SUN_MRN'),
('SUN_EVE'),
('TUE_BIB'),
('FRI_BIB'),
('WKD_CNF');
每当我的应用程序启动时,我总是得到以下错误消息: 将data.sql更改为: 生成以下错误消息:
尝试通过REST Post方法插入Student对象时得到以下错误 2020-10-08 18:50:08.799错误21708---[nio-8080-exec-7]O.A.C.C.C.[.[.[/].[dispatcherServlet]:servlet.Service()在路径[]上下文中的servlet[dispatcherServlet]引发异常[请求处理失败;嵌套异常是org.spri
尝试通过REST Post方法插入学生对象时出现以下错误 2020-10-08 18:50:08.799错误21708---[nio-8080-exec-7]o. a. c. c.C.[.[.]Servlet.service()的servlet[调度Servlet]在上下文中的路径[]抛出异常[请求处理失败;嵌套异常是org.springframework.dao.数据完整性违反异常:不能执行语句
以下是SQL部分,我在调试代码时出错: ORA-00001:唯一约束主键违反T_LIAV_AGENT_STATE_APPROVAL... 这是主键约束依赖的2列AV_NAME_ID,AV_STATE... 我没有重复的数据...你认为还有其他原因吗?
java } cardto.java 唯一索引或主键冲突:由:org.h2.jdbc.jdbcsqlexception使用:唯一索引或主键冲突:“public.car(ID)上的主键”;SQL语句:插入到car(可转换,engine_type,IS_Brooking,IS_Function,license_plate,Manufactor,rating,seat_count,id)值(?,?,?,
ORA-00001:违反唯一约束(DatabaseName.Constraint1) 这是否是因为insert all执行同步插入而序列没有增加?我尝试使用Insert ALL仅用于新的插入(不是从源表复制到目标表),我不想对每一行使用Insert query。这是我在尝试的一种研究。