【发布时间】:2018-08-18 13:54:01
【问题描述】:
在我的项目中,我将 MySQL 与 Hibernate 和 JPA 一起使用。我的实体都标有@ID @GeneratedValue(strategy = GenerationType.IDENTITY)。
尽管如此,Hibernate 在将新对象插入数据库时尝试从表 hibernate_sequence 中选择下一个 ID - 这显然失败了。
我检查了整个项目是否在某些实体上意外使用了不同的生成类型,但事实并非如此。还有什么可能导致这个问题?
这是我用来创建表的 SQL:
create table versioned_string_attribute (
id int primary key auto_increment not null,
timestamp timestamp,
value text
);
create table backend_address (
id int primary key auto_increment not null,
street_id int references versioned_string_attribute(id),
house_number_id int references versioned_string_attribute(id),
zip_code_id int references versioned_string_attribute(id),
town_id int references versioned_string_attribute(id),
addition_id int references versioned_string_attribute(id)
);
这是我的application.properties
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.driverClassName=com.mysql.jdbc.Driver
【问题讨论】:
标签: java mysql hibernate spring-boot