简体   繁体   English

为什么在使用策略GenerationType.IDENTITY时Hibernate尝试访问hibernate_sequence?

[英]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.

相关问题 Hibernate GenerationType.IDENTITY 不生成序列 ID - Hibernate GenerationType.IDENTITY not generating sequence ids Hibernate GenerationType.IDENTITY vs GenerationType.SEQUENCE - Hibernate GenerationType.IDENTITY vs GenerationType.SEQUENCE 全局配置Hibernate以使用GenerationType.IDENTITY - Configure Hibernate globally to use GenerationType.IDENTITY 休眠中的 GenerationType.AUTO 与 GenerationType.IDENTITY - GenerationType.AUTO vs GenerationType.IDENTITY in hibernate 手动将数据库中的数据插入到具有 hibernate_sequence @GeneratedValue(strategy = GenerationType.TABLE) 的表中 - Manually insert Data from database in table which has hibernate_sequence @GeneratedValue(strategy = GenerationType.TABLE) 带有生成器的Oracle JPA GenerationType.AUTO要求“ hibernate_sequence” - Oracle JPA GenerationType.AUTO with generator asks for “hibernate_sequence” 注释@Id 和@GeneratedValue(strategy = GenerationType.IDENTITY) 有什么用? 为什么世代类型是身份? - what is the use of annotations @Id and @GeneratedValue(strategy = GenerationType.IDENTITY)? Why the generationtype is identity? Hibernate和PostgreSQL:是否可以配置GenerationType.IDENTITY,其中每个id列的默认值来自共享序列? - Hibernate and PostgreSQL: Can I configure GenerationType.IDENTITY, where each id column's default value comes from a shared sequence? 休眠:@GeneratedValue(strategy = GenerationType - Hibernate: @GeneratedValue(strategy = GenerationType 使用 GenerationType.AUTO 的 h2 测试找不到序列“HIBERNATE_SEQUENCE” - Sequence "HIBERNATE_SEQUENCE" not found for h2 test with GenerationType.AUTO
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM