wanghongzhou opened a new issue, #6914:
URL: https://github.com/apache/incubator-seata/issues/6914
### Ⅰ. Issue Description
After upgrading my project to Seata-Spring 2.1, I encountered an issue
during startup. My Spring Boot project, which uses Spring Data JPA and Flyway,
fails to start when the database schema is not pre-existing. The error message
indicates that both entityManagerFactory and Flyway depend on DataSourceProxy
during their initialization. However, Seata’s DataSourceProxy checks for the
existence of the undo_log table, and when it’s not present, the application
fails to proceed.
In my project:
* Hibernate is configured with hbm2ddl.auto=update.
* Flyway migration scripts include the necessary DDL for creating the
undo_log table.
* I have also added an UndoLog entity class to allow Hibernate to
automatically create the table.
However, despite these configurations, Seata’s DataSourceProxy performs an
early check for the undo_log table during its initialization. This interferes
with the normal flow of Hibernate and Flyway table creation, causing a startup
failure even though the schema would normally be created by Hibernate or Flyway
during initialization.
### Ⅱ. Describe what happened
1. Set up a Spring Boot project with Seata-Spring 2.1, Spring Data JPA, and
Flyway.
2. Ensure the database does not have existing tables, including the undo_log
table.
3. Configure Hibernate with hbm2ddl.auto=update and include Flyway scripts
that create the undo_log table.
4. Add an UndoLog entity class for Hibernate to automatically create the
table.
5. Attempt to start the project.
```
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'entityManagerFactory' defined in class path resource
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
Failed to initialize dependency 'flyway' of LoadTimeWeaverAware bean
'entityManagerFactory': Error creating bean with name 'flyway' defined in class
path resource
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway'
threw exception with message: Error creating bean with name 'dataSource'
defined in class path resource
[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
in AT mode, undo_log table not exist
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:326)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:954)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625)
at
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
at
com.ivyark.app.account.service.AccountServiceApplication.main(AccountServiceApplication.java:24)
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'flyway' defined in class path resource
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway'
threw exception with message: Error creating bean with name 'dataSource'
defined in class path resource
[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
in AT mode, undo_log table not exist
at
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1355)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:313)
... 10 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception
with message: Error creating bean with name 'dataSource' defined in class path
resource
[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
in AT mode, undo_log table not exist
at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
... 20 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource' defined in class path resource
[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
in AT mode, undo_log table not exist
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:607)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at
org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getIfUnique(DefaultListableBeanFactory.java:2153)
at
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:172)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
... 21 common frames omitted
Caused by: java.lang.IllegalStateException: in AT mode, undo_log table not
exist
at
org.apache.seata.rm.datasource.DataSourceProxy.checkUndoLogTableExist(DataSourceProxy.java:176)
at
org.apache.seata.rm.datasource.DataSourceProxy.init(DataSourceProxy.java:111)
at
org.apache.seata.rm.datasource.DataSourceProxy.<init>(DataSourceProxy.java:97)
at
org.apache.seata.rm.datasource.DataSourceProxy.<init>(DataSourceProxy.java:82)
at
org.apache.seata.spring.annotation.datasource.SeataAutoDataSourceProxyCreator.buildProxy(SeataAutoDataSourceProxyCreator.java:113)
at
org.apache.seata.spring.annotation.datasource.SeataAutoDataSourceProxyCreator.wrapIfNecessary(SeataAutoDataSourceProxyCreator.java:87)
at
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:320)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:438)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1809)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600)
... 35 common frames omitted
```
### Ⅲ. Describe what you expected to happen
The project should start successfully, and Flyway or Hibernate should be
able to create the necessary tables, including undo_log.
### Ⅵ. Environment:
- JDK version(e.g. `java -version`): JDK 17
- Seata client/server version: Seata 2.1
- Database version: Mysql 8.0
- OS(e.g. `uname -a`): Windows 11
- Spring boot: 3.3.4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]