gpt4 book ai didi

java - 由于架构验证,Spring Boot 项目无法运行 : missing sequence [hibernate_sequence]

转载 作者:行者123 更新时间:2023-12-02 03:30:03 30 4
gpt4 key购买 nike

当我尝试运行 Spring Boot 和 Hibernate 应用程序时,我发现它失败的原因是:

org.hibernate.tool.schema.spi.SchemaManagementException:架构验证:缺少序列 [hibernate_sequence]

但我不明白这是为什么,因为我没有使用 Hibernate 序列。我在 Apache Derby 中的表格如下:

CREATE TABLE TEAM (
TEAM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
NAME VARCHAR(50) NOT NULL,
CONSTRAINT PK_TEAM PRIMARY KEY(Team_Id)
);

CREATE TABLE PLAYER (
PLAYER_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
NAME VARCHAR(50) NOT NULL,
NUM INTEGER NOT NULL,
POSITION VARCHAR(50) NOT NULL,
TEAM_ID INTEGER,
CONSTRAINT PK_PLAYER PRIMARY KEY(PLAYER_ID),
CONSTRAINT FK_PLAYER FOREIGN KEY(TEAM_ID) REFERENCES TEAM(TEAM_ID)
);

我的应用程序的 application.properties 文件是:

# Hibernate table generation.
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.DerbyTenSevenDialect
spring.jpa.show-sql=true

# Apache Derby settings
spring.datasource.driverClassName=org.apache.derby.jdbc.ClientDriver
spring.datasource.url=jdbc:derby://localhost:1527/Library
spring.datasource.username=username
spring.datasource.password=password`

涉及到的两个Java类是:

@Entity
@Table(name = "TEAM")
public class Team {

@Id
@Column(name = "TEAM_ID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer teamId;

@Column(name = "NAME")
private String name;

@OneToMany(cascade = CascadeType.ALL,
fetch = FetchType.EAGER,
mappedBy = "team")
private List<Player> players;

还有:

@Entity
@Table(name = "PLAYER")
public class Player {

@Id
@Column(name = "PLAYER_ID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer playerId;

@Column(name = "NAME")
private String name;

@Column(name = "NUM")
private int num;

@Column(name = "POSITION")
private String position;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TEAM_ID", nullable = true)
private Team team;

谁能告诉我哪里错了?

Maven 依赖项是:

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.14.2.0</version>
</dependency>
</dependencies>

最佳答案

您遇到的问题是因为缺少序列 hibernate_sequence 。您可以使用 create sequence <schema>.hibernate_sequence 在数据库上手动创建序列。有关创建序列的更多信息,请参阅 Derby请关注link

关于java - 由于架构验证,Spring Boot 项目无法运行 : missing sequence [hibernate_sequence],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50659505/

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