Spring Boot 2.2および関連するHibernate 5.4.xにアップデートするときに問題が発生します。
次のシーケンスジェネレーターがあります
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hilo_sequence_generator")
@GenericGenerator(
name = "hilo_sequence_generator",
strategy = "...",
parameters = {
@Parameter(name = "sequence_name", value = "XXX_SEQUENCE"),
@Parameter(name = "initial_value", value = "1"),
@Parameter(name = "increment_size", value = "10"),
@Parameter(name = "optimizer", value = "hilo")
})
private Long id;
SB 2.2/HB 5.4にアップデートすると、次の初期化エラーが発生します
org.hibernate.MappingException: The increment size of the sequence is set to [10] in the entity mapping while the associated database sequence increment size is [1]
DBシーケンスの増分サイズは1です。
Sequence "...xxx_sequence"
Type | Start | Minimum | Maximum | Increment | Cycles? | Cache
--------+-------+---------+---------------------+-----------+---------+-------
bigint | 1 | 1 | 9223372036854775807 | 1 | no | 1
ただし、私の理解では、hiloアルゴリズムの(ソフト)増分サイズは、DBの(ハード)増分サイズとは関係ありません。
これはHBのエラーですか、それとも何らかの方法で問題を回避できますか?
イェンスの質問へのWRT:
シーケンスはLiquibaseによって生成されます:
<changeSet author="GerdAschemann (generated)" id="1540300079577-1">
<createSequence sequenceName="rbl_sequence"/>
</changeSet>
これは、アプリケーションコンテキストのセットアップ/ Beanの初期化中に発生します。
2019-12-12 18:29:52.841 INFO 20076 --- [ main] o.h.j.i.u.LogHelper : {} HHH000204: Processing PersistenceUnitInfo [name: default]
2019-12-12 18:29:52.971 INFO 20076 --- [ main] o.h.Version : {} HHH000412: Hibernate Core {5.4.9.Final}
2019-12-12 18:29:53.127 INFO 20076 --- [ main] o.h.a.c.Version : {} HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-12-12 18:29:53.320 INFO 20076 --- [ main] o.h.d.Dialect : {} HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL95Dialect
2019-12-12 18:29:53.962 ERROR 20076 --- [ main] o.s.b.w.e.t.TomcatStarter : {} Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'batchDeleteEndpointConfiguration' defined in file [R:\codebase\reisebegleitung\app\app-guide\target\classes\de\db\vendo\rbl\guide\adapter\maintenanceEndpoint\BatchDeleteEndpointConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'maintenanceApplication' defined in file [R:\codebase\reisebegleitung\app\app-guide\target\classes\de\db\vendo\rbl\guide\application\MaintenanceApplication.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reisekettenRepositoryImpl' defined in file [R:\codebase\reisebegleitung\app\app-guide\target\classes\de\db\vendo\rbl\guide\adapter\domainJpa\ReisekettenRepositoryImpl.class]: Unsatisfied dependency expressed through constructor parameter 4; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reisekettenJpaRepository': Cannot create inner bean '(inner bean)#5b430541' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5b430541': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=de.db.vendo.rbl.guide.adapter.domainJpa.entity.SubscriptionRetryEntity]
2019-12-12 18:29:53.994 INFO 20076 --- [ main] o.a.c.c.StandardService : {} Stopping service [Tomcat]
検証を無効にしても何も変わりません
GHにサンプルプロジェクトを追加: https://github.com/ascheman/hibernate-so-59305427
スタックトレース:
2019-12-13 11:58:33.245 INFO 16796 --- [ main] n.a.d.s.b.h.HibernateProblemApplication : No active profile set, falling back to default profiles: default
2019-12-13 11:58:33.773 INFO 16796 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2019-12-13 11:58:33.858 INFO 16796 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 76ms. Found 1 JPA repository interfaces.
2019-12-13 11:58:34.194 INFO 16796 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-12-13 11:58:34.282 INFO 16796 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-12-13 11:58:35.149 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOGLOCK
2019-12-13 11:58:35.157 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))
2019-12-13 11:58:35.162 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOGLOCK
2019-12-13 11:58:35.165 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : DELETE FROM PUBLIC.DATABASECHANGELOGLOCK
2019-12-13 11:58:35.166 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : INSERT INTO PUBLIC.DATABASECHANGELOGLOCK (ID, LOCKED) VALUES (1, FALSE)
2019-12-13 11:58:35.169 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT LOCKED FROM PUBLIC.DATABASECHANGELOGLOCK WHERE ID=1
2019-12-13 11:58:35.176 INFO 16796 --- [ main] l.lockservice.StandardLockService : Successfully acquired change log lock
2019-12-13 11:58:36.825 INFO 16796 --- [ main] l.c.StandardChangeLogHistoryService : Creating database history table with name: PUBLIC.DATABASECHANGELOG
2019-12-13 11:58:36.826 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : CREATE TABLE PUBLIC.DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED INT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10))
2019-12-13 11:58:36.827 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOG
2019-12-13 11:58:36.827 INFO 16796 --- [ main] l.c.StandardChangeLogHistoryService : Reading from PUBLIC.DATABASECHANGELOG
2019-12-13 11:58:36.827 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT * FROM PUBLIC.DATABASECHANGELOG ORDER BY DATEEXECUTED ASC, ORDEREXECUTED ASC
2019-12-13 11:58:36.828 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOGLOCK
2019-12-13 11:58:36.833 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : CREATE SEQUENCE PUBLIC.xxx_sequence
2019-12-13 11:58:36.835 INFO 16796 --- [ main] liquibase.changelog.ChangeSet : Sequence xxx_sequence created
2019-12-13 11:58:36.835 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : CREATE TABLE PUBLIC.xxx_entity (id BIGINT NOT NULL, CONSTRAINT kunde_pkey PRIMARY KEY (id))
2019-12-13 11:58:36.836 INFO 16796 --- [ main] liquibase.changelog.ChangeSet : Table xxx_entity created
2019-12-13 11:58:36.836 INFO 16796 --- [ main] liquibase.changelog.ChangeSet : ChangeSet classpath:/db/db.changelog.xml::1::GerdAschemann ran successfully in 3ms
2019-12-13 11:58:36.837 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT MAX(ORDEREXECUTED) FROM PUBLIC.DATABASECHANGELOG
2019-12-13 11:58:36.840 INFO 16796 --- [ main] liquibase.executor.jvm.JdbcExecutor : INSERT INTO PUBLIC.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('1', 'GerdAschemann', 'classpath:/db/db.changelog.xml', NOW(), 1, '8:c491fb651a899536b626ee5370713ff7', 'createSequence sequenceName=xxx_sequence; createTable tableName=xxx_entity', '', 'EXECUTED', NULL, NULL, '3.8.2', '6234716828')
2019-12-13 11:58:36.850 INFO 16796 --- [ main] l.lockservice.StandardLockService : Successfully released change log lock
2019-12-13 11:58:36.947 INFO 16796 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2019-12-13 11:58:37.007 INFO 16796 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.9.Final}
2019-12-13 11:58:37.152 INFO 16796 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-12-13 11:58:37.251 INFO 16796 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-12-13 11:58:37.456 WARN 16796 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=net.aschemann.demo.spring.boot.hibernateproblem.XxxEntity]
2019-12-13 11:58:37.456 INFO 16796 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-12-13 11:58:37.458 INFO 16796 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2019-12-13 11:58:37.465 INFO 16796 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-13 11:58:37.475 ERROR 16796 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=net.aschemann.demo.spring.boot.hibernateproblem.XxxEntity]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1796) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:595) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:517) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.Java:323) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:321) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:202) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1108) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:868) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:550) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:747) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:397) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:315) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1226) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1215) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at net.aschemann.demo.spring.boot.hibernateproblem.HibernateProblemApplication.main(HibernateProblemApplication.Java:10) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=net.aschemann.demo.spring.boot.hibernateproblem.XxxEntity]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.Java:403) ~[spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.Java:378) ~[spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.Java:341) ~[spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1855) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1792) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 15 common frames omitted
Caused by: org.hibernate.MappingException: Could not instantiate id generator [entity-name=net.aschemann.demo.spring.boot.hibernateproblem.XxxEntity]
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.Java:124) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.Java:344) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.internal.SessionFactoryImpl.lambda$new$1(SessionFactoryImpl.Java:292) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at Java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.Java:184) ~[na:1.8.0_192-ea]
at Java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.Java:175) ~[na:1.8.0_192-ea]
at Java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.Java:1628) ~[na:1.8.0_192-ea]
at Java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.Java:481) ~[na:1.8.0_192-ea]
at Java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.Java:471) ~[na:1.8.0_192-ea]
at Java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.Java:151) ~[na:1.8.0_192-ea]
at Java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.Java:174) ~[na:1.8.0_192-ea]
at Java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.Java:234) ~[na:1.8.0_192-ea]
at Java.util.stream.ReferencePipeline.forEach(ReferencePipeline.Java:418) ~[na:1.8.0_192-ea]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.Java:291) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.Java:462) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.Java:1237) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.Java:58) ~[spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.Java:365) ~[spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.Java:391) ~[spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 19 common frames omitted
Caused by: org.hibernate.MappingException: The increment size of the [XXX_SEQUENCE] sequence is set to [10] in the entity mapping while the associated database sequence increment size is [1].
at org.hibernate.id.enhanced.SequenceStyleGenerator.configure(SequenceStyleGenerator.Java:257) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.Java:118) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
... 36 common frames omitted
Process finished with exit code 1
@Parameter(name = "increment_size"、value = "10")を@Parameter(name = "increment_size"、value = "1")に変更すると、これでうまくいくと思います。なぜ値を10に設定するのですか?