Spring boot JPA 事务正在提交,但记录未插入

问题描述 投票:0回答:1

我们最近将 java 8 升级到 java 17,并将 Spring 框架从

5.3.31
升级到
6.1.3
现在数据没有插入到数据库中,并且过去在
5.3.31
中工作正常。

Hibernate ORM 核心版本是

6.4.3.Final

我们有以下多个数据源:


@Configuration
@EnableConfigurationProperties
@Slf4j
public class DataSourceConfig {


  @Primary
  @Bean(destroyMethod = "")
  @ConfigurationProperties(prefix = "spring.datasource.primary")
  public DataSource primaryDataSource(@Value("${spring.datasource.primary.username}")
  String userName) {
    HikariDataSource dataSource = DataSourceBuilder.create().type(HikariDataSource.class).build();
    // set datasource properties...
    // ..
    return dataSource;
  }


  @Bean(destroyMethod = "", name = "secondaryDataSource")
  @ConfigurationProperties(prefix = "spring.datasource.secondary")
  public DataSource secondaryDataSource(@Value("${spring.datasource.secondary.username}")
  String userName) {
    HikariDataSource dataSource = DataSourceBuilder.create().type(HikariDataSource.class).build();
    // ... some datasource configuration
    return dataSource;
  }
// .. some more datasource beans
}


我们将

@Transactional
放在所有存储库上,如下所示:

@Repository
@Transactional
public interface JobDetailsRepository extends JpaRepository<JobDetails, String> {

}

我们启用了事务调试日志记录,并且出现以下日志。正在创建并提交新事务,但我们没有看到数据插入到数据库中。

2024-02-19T16:40:19.138Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.s.orm.jpa.JpaTransactionManager        : Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2024-02-19T16:40:19.139Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.s.orm.jpa.JpaTransactionManager        : Opened new EntityManager [SessionImpl(1877545655<open>)] for JPA transaction
2024-02-19T16:40:19.139Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.e.t.internal.TransactionImpl         : On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2024-02-19T16:40:19.139Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.e.t.internal.TransactionImpl         : begin
2024-02-19T16:40:19.141Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.s.orm.jpa.JpaTransactionManager        : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@651179c7]
2024-02-19T16:40:19.141Z TRACE 10849 --- [TASK_MANAGER] [eline Service-2] o.s.t.i.TransactionInterceptor           : Getting transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]
2024-02-19T16:40:19.141Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.j.internal.PersistenceUnitUtilImpl   : jakarta.persistence.PersistenceUnitUtil.getIdentifier may not be able to read identifier of a detached entity
2024-02-19T16:40:19.141Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] org.hibernate.orm.sql.exec               : Skipping reading Query result cache data: cache-enabled = false, cache-mode = IGNORE
2024-02-19T16:40:19.141Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] org.hibernate.orm.results                : Initializer list:
      com.oracle.cp360pipeline.taskmanager.entity.Job -> EntityResultInitializer(com.oracle.cp360pipeline.taskmanager.entity.Job)@130558238 (SingleTableEntityPersister(com.oracle.cp360pipeline.taskmanager.entity.Job))

2024-02-19T16:40:19.142Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] org.hibernate.SQL                        : select j1_0.JOB_ID,j1_0.APP_CODE,j1_0.CURRENT_JOB_STEP_TYPE,j1_0.FROM_DT,j1_0."W$_INSERT_DT",j1_0.JOB_END_DT,j1_0.JOB_START_DT,j1_0.JOB_TYPE,j1_0.STATUS,j1_0.TO_DT,j1_0."W$_UPDATE_DT",j1_0."W$_UPDATED_BY" from OPS_JOB j1_0 where j1_0.JOB_ID=?
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.r.j.i.LogicalConnectionManagedImpl   : Skipping aggressive release of JDBC Connection after-statement due to held resources
2024-02-19T16:40:19.144Z TRACE 10849 --- [TASK_MANAGER] [eline Service-2] o.s.t.i.TransactionInterceptor           : Completing transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.s.orm.jpa.JpaTransactionManager        : Initiating transaction commit
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.s.orm.jpa.JpaTransactionManager        : Committing JPA transaction on EntityManager [SessionImpl(1877545655<open>)]
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.e.t.internal.TransactionImpl         : committing
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.e.i.AbstractFlushingEventListener    : Processing flush-time cascades
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.e.i.AbstractFlushingEventListener    : Dirty checking collections
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.e.i.AbstractFlushingEventListener    : Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2024-02-19T16:40:19.144Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.e.i.AbstractFlushingEventListener    : Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2024-02-19T16:40:19.145Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.hibernate.internal.util.EntityPrinter  : Listing entities:
2024-02-19T16:40:19.145Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.hibernate.internal.util.EntityPrinter  : com.oracle.cp360pipeline.taskmanager.entity.Job{fromDate=2022-05-15 10:13:22.546, jobEndDate=null, jobID=CPAnalytics.Incremental.CPAnalytics.2402151018386, updateDate=null, currentJobStepType=null, updatedBy=null, jobStartDate=2024-02-19 16:40:19.138, toDate=null, insertDate=2024-02-19 16:40:19.138, appCode=JIRA_SD_TRANSFORM, jobType=Scheduled, status=New}
2024-02-19T16:40:19.145Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] org.hibernate.SQL                        : insert into OPS_JOB (APP_CODE,CURRENT_JOB_STEP_TYPE,FROM_DT,"W$_INSERT_DT",JOB_END_DT,JOB_START_DT,JOB_TYPE,STATUS,TO_DT,"W$_UPDATE_DT","W$_UPDATED_BY",JOB_ID) values (?,?,?,?,?,?,?,?,?,?,?,?)
2024-02-19T16:40:19.147Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.r.j.i.LogicalConnectionManagedImpl   : Initiating JDBC connection release from afterStatement
2024-02-19T16:40:19.149Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] com.zaxxer.hikari.pool.ProxyConnection   : HikariPool-1 - Executed rollback on connection oracle.jdbc.driver.T4CConnection@5fd31df7 due to dirty commit state on close().
2024-02-19T16:40:19.149Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Reset (autoCommit) on connection oracle.jdbc.driver.T4CConnection@5fd31df7
2024-02-19T16:40:19.150Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.r.j.i.LogicalConnectionManagedImpl   : Initiating JDBC connection release from afterTransaction
2024-02-19T16:40:19.150Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.h.r.j.i.LogicalConnectionManagedImpl   : Initiating JDBC connection release from afterTransaction
2024-02-19T16:40:19.150Z DEBUG 10849 --- [TASK_MANAGER] [eline Service-2] o.s.orm.jpa.JpaTransactionManager        : Closing JPA EntityManager [SessionImpl(1877545655<open>)] after transaction

光配置:

2024-02-19T16:34:23.913Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : HikariPool-1 - configuration:
2024-02-19T16:34:23.916Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : allowPoolSuspension.............false
2024-02-19T16:34:23.917Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : autoCommit......................true
2024-02-19T16:34:23.917Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : catalog.........................none
2024-02-19T16:34:23.917Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : connectionInitSql...............none
2024-02-19T16:34:23.917Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : connectionTestQuery.............none
2024-02-19T16:34:23.917Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : connectionTimeout...............30000
2024-02-19T16:34:23.918Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : dataSource......................none
2024-02-19T16:34:23.918Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : dataSourceClassName.............none
2024-02-19T16:34:23.918Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : dataSourceJNDI..................none
2024-02-19T16:34:23.918Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : dataSourceProperties............{password=<masked>}
2024-02-19T16:34:23.918Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : driverClassName................."oracle.jdbc.OracleDriver"
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : exceptionOverrideClassName......none
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : healthCheckProperties...........{}
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : healthCheckRegistry.............none
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : idleTimeout.....................30000
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : initializationFailTimeout.......1
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : isolateInternalQueries..........false
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : jdbcUrl.........................jdbc:oracle:thin:@cp360dev_low?TNS_ADMIN=***
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : keepaliveTime...................0
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : leakDetectionThreshold..........0
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : maxLifetime.....................1800000
2024-02-19T16:34:23.919Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : maximumPoolSize.................10
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : metricRegistry..................none
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : metricsTrackerFactory...........none
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : minimumIdle.....................2
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : password........................<masked>
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : poolName........................"HikariPool-1"
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : readOnly........................false
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : registerMbeans..................false
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : scheduledExecutor...............none
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : schema..........................none
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : threadFactory...................internal
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : transactionIsolation............default
2024-02-19T16:34:23.920Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : username........................"****"
2024-02-19T16:34:23.921Z DEBUG 10849 --- [TASK_MANAGER] [           main] com.zaxxer.hikari.HikariConfig           : validationTimeout...............5000
spring spring-boot hibernate jpa ojdbc
1个回答
0
投票

HikariPool-1 - 由于 close() 上的脏提交状态,在连接 oracle.jdbc.driver.T4CConnection@5fd31df7 上执行回滚。

你确定你的代码可以正常工作吗?

© www.soinside.com 2019 - 2024. All rights reserved.