[英]Why is Hibernate trying to access hibernate_sequence when using strategy GenerationType.IDENTITY?
In my project, I am using MySQL with Hibernate and JPA. 在我的项目中,我将MySQL与Hibernate和JPA结合使用。 My entities are all annotated with
@ID @GeneratedValue(strategy = GenerationType.IDENTITY)
. 我的实体都用
@ID @GeneratedValue(strategy = GenerationType.IDENTITY)
注释。
Nevertheless, Hibernate tries to select the next ID from the table hibernate_sequence
when inserting new objects into the database - which fails obviously. 但是,当将新对象插入数据库时,Hibernate会尝试从表
hibernate_sequence
选择下一个ID-显然会失败。
I checked for the whole project whether a different generation type was used by accident on some entity, but this is not the case. 我检查了整个项目,是否偶然在某个实体上使用了不同的发电类型,但事实并非如此。 What else could cause this problem?
还有什么可能导致此问题?
This is the SQL i use to create my tables: 这是我用来创建表的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)
);
And here is my application.properties
这是我的
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
From the docs( https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#common-application-properties ) the property: 在docs( https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#common-application-properties )中,该属性为:
spring.jpa.hibernate.use-new-id-generator-mappings= # Whether to use Hibernate's newer IdentifierGenerator for AUTO, TABLE and SEQUENCE. spring.jpa.hibernate.use-new-id-generator-mappings =#是否对AUTO,TABLE和SEQUENCE使用Hibernate更新的IdentifierGenerator。
So I solved this issue by adding spring.jpa.hibernate.use-new-id-generator-mappings=false
所以我通过添加
spring.jpa.hibernate.use-new-id-generator-mappings=false
解决了这个问题
More details about this: https://vladmihalcea.com/from-jpa-to-hibernates-legacy-and-enhanced-identifier-generators/ 有关此的更多详细信息: https : //vladmihalcea.com/from-jpa-to-hibernates-legacy-and-enhanced-identifier-generators/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.