我在WebSphere容器中有一个spring应用程序。
我尝试使用liquibase初始化数据。
这是我的DataSource配置:
@Bean
public JndiTemplate jndi() {
return new JndiTemplate();
}
@Bean
public PlatformTransactionManager transactionManager() {
return new WebSphereUowTransactionManager();
}
@Bean(name = "primary")
public AbstractEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPersistenceUnitName(PERSTESTENCE_UNIT_NAME);
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
jpaVendorAdapter.setGenerateDdl(true);
jpaVendorAdapter.setDatabase(Database.H2);
entityManagerFactory.setJpaVendorAdapter(jpaVendorAdapter);
return entityManagerFactory;
}
@Bean
public DataSource dataSource() throws NamingException {
return jndi().lookup(DATA_SOURCE_ADDRESS, DataSource.class);
}
这是运行数据库初始化的代码:
@Startup
@Singleton
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class Startup {
@Autowired
private DbInit dbInit;
@PostConstruct
public void initialize() {
try {
dbInit.doMigrations(null);
} catch (SQLException | LiquibaseException e) {
LOG.error(e);
}
}
我在应用程序启动时遇到异常:
Caused by: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.sql.SQLException: DSRA9350E: Operation Connection.rollback is not allowed during a global transaction.
at liquibase.database.AbstractJdbcDatabase.rollback(AbstractJdbcDatabase.java:1143)
at liquibase.lockservice.StandardLockService.acquireLock(StandardLockService.java:197)
... 142 more
Caused by: liquibase.exception.DatabaseException: java.sql.SQLException: DSRA9350E: Operation Connection.rollback is not allowed during a global transaction.
at liquibase.database.jvm.JdbcConnection.rollback(JdbcConnection.java:340)
at liquibase.database.AbstractJdbcDatabase.rollback(AbstractJdbcDatabase.java:1141)
... 143 more
Caused by: java.sql.SQLException: DSRA9350E: Operation Connection.rollback is not allowed during a global transactionи.
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.rollback(WSJdbcConnection.java:3372)
at liquibase.database.jvm.JdbcConnection.rollback(JdbcConnection.java:337)
... 144 more
我知道我无法在容器管理的交易中使用rollback()
,但我不知道如何为liquibase配置此功能。
我已尝试在WS DataSource配置中设置Non-transactional data source
属性,但它没有帮助。
我该如何解决这个问题?