小编Has*_*Aga的帖子

Spring data JDBC不创建表

我正在尝试使用Spring data JDBC将一个名为Instructor的实体持久保存到 H2 内存数据库中,如果我手动创建表,一切正常,否则我会收到此错误(我在底部添加了整个错误堆栈跟踪):

org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "INSTRUCTOR" not found; SQL statement:
INSERT INTO "INSTRUCTOR" ("NAME") VALUES (?) [42102-200]
Run Code Online (Sandbox Code Playgroud)

这是实体类:

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Persistable;
import org.springframework.data.relational.core.mapping.Table;

@Data
@Table
public class Instructor{

    @Id
    private String id;
    private String name;
    
}
Run Code Online (Sandbox Code Playgroud)

控制器使用此存储库:

import org.springframework.data.repository.CrudRepository;
import test.com.small.school.model.Instructor;

public interface InstructorRepository extends CrudRepository<Instructor, String> {
}
Run Code Online (Sandbox Code Playgroud)

控制器:

@Controller
@RequestMapping("/add")
public class AddController implements Serializable {
    private static final long serialVersionUID = 1L;

    private final InstructorRepository instructorRepo;

    @Autowired
    public AddController(InstructorRepository …
Run Code Online (Sandbox Code Playgroud)

java h2 spring-boot spring-data-jdbc

1
推荐指数
1
解决办法
1689
查看次数

标签 统计

h2 ×1

java ×1

spring-boot ×1

spring-data-jdbc ×1