Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringData/JPA/Hibernate:不提交更改_Spring_Hibernate_Spring Data - Fatal编程技术网

SpringData/JPA/Hibernate:不提交更改

SpringData/JPA/Hibernate:不提交更改,spring,hibernate,spring-data,Spring,Hibernate,Spring Data,我正在尝试执行一个查询,该查询必须从子选择中删除项 环境: public interface MySecondEntityRepository extends JpaRepository<MySecondEntity, UUID> { @Modifying @Transactional(propagation = Propagation.REQUIRES_NEW) @Query("DELETE FROM MySecondEntity e WHERE e.uui

我正在尝试执行一个查询,该查询必须从子选择中删除项

环境:

public interface MySecondEntityRepository extends JpaRepository<MySecondEntity, UUID> {
    @Modifying
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Query("DELETE FROM MySecondEntity e WHERE e.uuid IN ("
             + "SELECT e2.uuid "
             + "FROM MySecondEntity e2, MyEntity e1 "
             + "WHERE e2.entityUUID = e1.uuid "
             + "AND e1.uuid = :uuid "
             + "AND e1.*** = ..."
             + "AND e1.*** = ..."
         + ")")
    public void deleteByEntityUUID(@Param("uuid") UUID entityUUID, ...);
}
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
SQL | insert into HT_my_entity select ...
SQL | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,073 | DEBUG | AnnotationTransactionAttri:108  | Adding transactional method 'DefaultJpaRepositoryImpl.deleteByEntityUUID' with attribute: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,073 | DEBUG | JpaTransactionManager     :367  | Creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,074 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,075 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,075 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,075 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,076 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,076 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,076 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@7d7135]
14:41:45,078 | DEBUG | JpaTransactionManager     :334  | Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,079 | DEBUG | JpaTransactionManager     :417  | Suspending current transaction, creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]
14:41:45,082 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] for JPA transaction
14:41:45,082 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,082 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,083 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,083 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,083 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,084 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@1b46a77]
14:41:45,223 | DEBUG | SQL                       :109  | insert into HT_my_entity select my_second_0_.uuid as uuid from my_second_entity my_second_0_ where my_second_0_.uuid in (select my_second_1_.uuid from my_second_entity my_second_1_ cross join my_entity my_entity_2_ where my_second_1_.entity_uuid=my_entity_2_.uuid and my_entity_2_.uuid=?)
14:41:45,232 | DEBUG | SQL                       :109  | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,333 | DEBUG | JpaTransactionManager     :755  | Initiating transaction commit
14:41:45,334 | DEBUG | JpaTransactionManager     :512  | Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880]
14:41:45,335 | DEBUG | AbstractTransactionImpl   :175  | committing
14:41:45,388 | DEBUG | JdbcTransaction           :113  | committed JDBC Connection
14:41:45,389 | DEBUG | JdbcTransaction           :126  | re-enabling autocommit
14:41:45,393 | DEBUG | JpaTransactionManager     :600  | Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] after transaction
14:41:45,394 | DEBUG | EntityManagerFactoryUtils :432  | Closing JPA EntityManager
14:41:45,396 | DEBUG | LogicalConnectionImpl     :246  | Releasing JDBC connection
14:41:45,397 | DEBUG | LogicalConnectionImpl     :264  | Released JDBC connection
  • Wildfly 8.2
  • Spring框架4.1.6
  • 弹簧数据1.8.0
  • 休眠4.3.10
  • MySQL 5
这是存储库:

public interface MySecondEntityRepository extends JpaRepository<MySecondEntity, UUID> {
    @Modifying
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Query("DELETE FROM MySecondEntity e WHERE e.uuid IN ("
             + "SELECT e2.uuid "
             + "FROM MySecondEntity e2, MyEntity e1 "
             + "WHERE e2.entityUUID = e1.uuid "
             + "AND e1.uuid = :uuid "
             + "AND e1.*** = ..."
             + "AND e1.*** = ..."
         + ")")
    public void deleteByEntityUUID(@Param("uuid") UUID entityUUID, ...);
}
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
SQL | insert into HT_my_entity select ...
SQL | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,073 | DEBUG | AnnotationTransactionAttri:108  | Adding transactional method 'DefaultJpaRepositoryImpl.deleteByEntityUUID' with attribute: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,073 | DEBUG | JpaTransactionManager     :367  | Creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,074 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,075 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,075 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,075 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,076 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,076 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,076 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@7d7135]
14:41:45,078 | DEBUG | JpaTransactionManager     :334  | Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,079 | DEBUG | JpaTransactionManager     :417  | Suspending current transaction, creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]
14:41:45,082 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] for JPA transaction
14:41:45,082 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,082 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,083 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,083 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,083 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,084 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@1b46a77]
14:41:45,223 | DEBUG | SQL                       :109  | insert into HT_my_entity select my_second_0_.uuid as uuid from my_second_entity my_second_0_ where my_second_0_.uuid in (select my_second_1_.uuid from my_second_entity my_second_1_ cross join my_entity my_entity_2_ where my_second_1_.entity_uuid=my_entity_2_.uuid and my_entity_2_.uuid=?)
14:41:45,232 | DEBUG | SQL                       :109  | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,333 | DEBUG | JpaTransactionManager     :755  | Initiating transaction commit
14:41:45,334 | DEBUG | JpaTransactionManager     :512  | Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880]
14:41:45,335 | DEBUG | AbstractTransactionImpl   :175  | committing
14:41:45,388 | DEBUG | JdbcTransaction           :113  | committed JDBC Connection
14:41:45,389 | DEBUG | JdbcTransaction           :126  | re-enabling autocommit
14:41:45,393 | DEBUG | JpaTransactionManager     :600  | Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] after transaction
14:41:45,394 | DEBUG | EntityManagerFactoryUtils :432  | Closing JPA EntityManager
14:41:45,396 | DEBUG | LogicalConnectionImpl     :246  | Releasing JDBC connection
14:41:45,397 | DEBUG | LogicalConnectionImpl     :264  | Released JDBC connection
当我手动执行
选择…
时,我会得到要删除的正确UUID。但是当spring/hibernate执行它们时,即使在
传播的情况下,事务也不会提交。没有引发异常

完整日志:

public interface MySecondEntityRepository extends JpaRepository<MySecondEntity, UUID> {
    @Modifying
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Query("DELETE FROM MySecondEntity e WHERE e.uuid IN ("
             + "SELECT e2.uuid "
             + "FROM MySecondEntity e2, MyEntity e1 "
             + "WHERE e2.entityUUID = e1.uuid "
             + "AND e1.uuid = :uuid "
             + "AND e1.*** = ..."
             + "AND e1.*** = ..."
         + ")")
    public void deleteByEntityUUID(@Param("uuid") UUID entityUUID, ...);
}
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
SQL | insert into HT_my_entity select ...
SQL | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,073 | DEBUG | AnnotationTransactionAttri:108  | Adding transactional method 'DefaultJpaRepositoryImpl.deleteByEntityUUID' with attribute: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,073 | DEBUG | JpaTransactionManager     :367  | Creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,074 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,075 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,075 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,075 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,076 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,076 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,076 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@7d7135]
14:41:45,078 | DEBUG | JpaTransactionManager     :334  | Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,079 | DEBUG | JpaTransactionManager     :417  | Suspending current transaction, creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]
14:41:45,082 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] for JPA transaction
14:41:45,082 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,082 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,083 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,083 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,083 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,084 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@1b46a77]
14:41:45,223 | DEBUG | SQL                       :109  | insert into HT_my_entity select my_second_0_.uuid as uuid from my_second_entity my_second_0_ where my_second_0_.uuid in (select my_second_1_.uuid from my_second_entity my_second_1_ cross join my_entity my_entity_2_ where my_second_1_.entity_uuid=my_entity_2_.uuid and my_entity_2_.uuid=?)
14:41:45,232 | DEBUG | SQL                       :109  | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,333 | DEBUG | JpaTransactionManager     :755  | Initiating transaction commit
14:41:45,334 | DEBUG | JpaTransactionManager     :512  | Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880]
14:41:45,335 | DEBUG | AbstractTransactionImpl   :175  | committing
14:41:45,388 | DEBUG | JdbcTransaction           :113  | committed JDBC Connection
14:41:45,389 | DEBUG | JdbcTransaction           :126  | re-enabling autocommit
14:41:45,393 | DEBUG | JpaTransactionManager     :600  | Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] after transaction
14:41:45,394 | DEBUG | EntityManagerFactoryUtils :432  | Closing JPA EntityManager
14:41:45,396 | DEBUG | LogicalConnectionImpl     :246  | Releasing JDBC connection
14:41:45,397 | DEBUG | LogicalConnectionImpl     :264  | Released JDBC connection
我的尝试:

public interface MySecondEntityRepository extends JpaRepository<MySecondEntity, UUID> {
    @Modifying
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Query("DELETE FROM MySecondEntity e WHERE e.uuid IN ("
             + "SELECT e2.uuid "
             + "FROM MySecondEntity e2, MyEntity e1 "
             + "WHERE e2.entityUUID = e1.uuid "
             + "AND e1.uuid = :uuid "
             + "AND e1.*** = ..."
             + "AND e1.*** = ..."
         + ")")
    public void deleteByEntityUUID(@Param("uuid") UUID entityUUID, ...);
}
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
SQL | insert into HT_my_entity select ...
SQL | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,073 | DEBUG | AnnotationTransactionAttri:108  | Adding transactional method 'DefaultJpaRepositoryImpl.deleteByEntityUUID' with attribute: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,073 | DEBUG | JpaTransactionManager     :367  | Creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,074 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,075 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,075 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,075 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,076 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,076 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,076 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@7d7135]
14:41:45,078 | DEBUG | JpaTransactionManager     :334  | Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,079 | DEBUG | JpaTransactionManager     :417  | Suspending current transaction, creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]
14:41:45,082 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] for JPA transaction
14:41:45,082 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,082 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,083 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,083 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,083 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,084 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@1b46a77]
14:41:45,223 | DEBUG | SQL                       :109  | insert into HT_my_entity select my_second_0_.uuid as uuid from my_second_entity my_second_0_ where my_second_0_.uuid in (select my_second_1_.uuid from my_second_entity my_second_1_ cross join my_entity my_entity_2_ where my_second_1_.entity_uuid=my_entity_2_.uuid and my_entity_2_.uuid=?)
14:41:45,232 | DEBUG | SQL                       :109  | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,333 | DEBUG | JpaTransactionManager     :755  | Initiating transaction commit
14:41:45,334 | DEBUG | JpaTransactionManager     :512  | Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880]
14:41:45,335 | DEBUG | AbstractTransactionImpl   :175  | committing
14:41:45,388 | DEBUG | JdbcTransaction           :113  | committed JDBC Connection
14:41:45,389 | DEBUG | JdbcTransaction           :126  | re-enabling autocommit
14:41:45,393 | DEBUG | JpaTransactionManager     :600  | Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] after transaction
14:41:45,394 | DEBUG | EntityManagerFactoryUtils :432  | Closing JPA EntityManager
14:41:45,396 | DEBUG | LogicalConnectionImpl     :246  | Releasing JDBC connection
14:41:45,397 | DEBUG | LogicalConnectionImpl     :264  | Released JDBC connection
  • 传播。必需的
    传播。需要新的
  • 方法调用后的
    .flush()
  • 展开子查询以测试它。它工作正常
  • 更新Spring数据/Hibernate
注意:

public interface MySecondEntityRepository extends JpaRepository<MySecondEntity, UUID> {
    @Modifying
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Query("DELETE FROM MySecondEntity e WHERE e.uuid IN ("
             + "SELECT e2.uuid "
             + "FROM MySecondEntity e2, MyEntity e1 "
             + "WHERE e2.entityUUID = e1.uuid "
             + "AND e1.uuid = :uuid "
             + "AND e1.*** = ..."
             + "AND e1.*** = ..."
         + ")")
    public void deleteByEntityUUID(@Param("uuid") UUID entityUUID, ...);
}
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
SQL | insert into HT_my_entity select ...
SQL | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,073 | DEBUG | AnnotationTransactionAttri:108  | Adding transactional method 'DefaultJpaRepositoryImpl.deleteByEntityUUID' with attribute: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,073 | DEBUG | JpaTransactionManager     :367  | Creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,074 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,075 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,075 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,075 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,076 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,076 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,076 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@7d7135]
14:41:45,078 | DEBUG | JpaTransactionManager     :334  | Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@cd414] for JPA transaction
14:41:45,079 | DEBUG | JpaTransactionManager     :417  | Suspending current transaction, creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]
14:41:45,082 | DEBUG | JpaTransactionManager     :371  | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] for JPA transaction
14:41:45,082 | DEBUG | AbstractTransactionImpl   :160  | begin
14:41:45,082 | DEBUG | LogicalConnectionImpl     :226  | Obtaining JDBC connection
14:41:45,083 | DEBUG | LogicalConnectionImpl     :232  | Obtained JDBC connection
14:41:45,083 | DEBUG | JdbcTransaction           :69   | initial autocommit status: true
14:41:45,083 | DEBUG | JdbcTransaction           :71   | disabling autocommit
14:41:45,084 | DEBUG | JpaTransactionManager     :403  | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@1b46a77]
14:41:45,223 | DEBUG | SQL                       :109  | insert into HT_my_entity select my_second_0_.uuid as uuid from my_second_entity my_second_0_ where my_second_0_.uuid in (select my_second_1_.uuid from my_second_entity my_second_1_ cross join my_entity my_entity_2_ where my_second_1_.entity_uuid=my_entity_2_.uuid and my_entity_2_.uuid=?)
14:41:45,232 | DEBUG | SQL                       :109  | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,333 | DEBUG | JpaTransactionManager     :755  | Initiating transaction commit
14:41:45,334 | DEBUG | JpaTransactionManager     :512  | Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880]
14:41:45,335 | DEBUG | AbstractTransactionImpl   :175  | committing
14:41:45,388 | DEBUG | JdbcTransaction           :113  | committed JDBC Connection
14:41:45,389 | DEBUG | JdbcTransaction           :126  | re-enabling autocommit
14:41:45,393 | DEBUG | JpaTransactionManager     :600  | Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@35e880] after transaction
14:41:45,394 | DEBUG | EntityManagerFactoryUtils :432  | Closing JPA EntityManager
14:41:45,396 | DEBUG | LogicalConnectionImpl     :246  | Releasing JDBC connection
14:41:45,397 | DEBUG | LogicalConnectionImpl     :264  | Released JDBC connection
  • 出于性能原因,我不在
    MyEntity
    中包含
    MySecondEntity
    MyEntity
    可以有10k+
    MySecondEntity
    。我知道我可以使用延迟抓取,但实际上,实体被映射到数据传输对象,这会导致映射过程出现问题。另外,我不希望检索所有的数据来删除它们
  • 已定义
  • 已定义
  • 该方法直接从
    @RestController
    调用

第二个选项:事务以静默方式结束/数据库中没有更改。是否对删除的实体进行版本控制?也就是说,actaul SQL是否在where子句中包含版本比较?否,实体没有版本控制,但它们通过使用
@EntityListeners
进行审核(在字段上:
@CreatedDate
@CreatedBy
@LastModifiedDate
@LastModifiedBy
)。当由Hibernate执行时,您应该调试delete语句的结果(是否删除了任何行)。我建议在调查时将org.hibernate日志级别设置为跟踪。我不认为事务没有提交,我宁愿说子查询中的where子句没有选择任何行(可能参数没有被Spring数据或Hibernate正确绑定)。我添加了
org.Hibernate
/
org.springframework.transaction
日志级别到
TRACE
。正如它所说的,事务已提交,但相关行未被删除。我的第一个想法是您所说的:子查询不选择任何行。这就是为什么我手动测试,但我成功地获得了行。如何查看参数是否未正确绑定?第二个选项:事务以静默方式结束/数据库中没有更改。是否对删除的实体进行版本控制?也就是说,actaul SQL是否在where子句中包含版本比较?否,实体没有版本控制,但它们通过使用
@EntityListeners
进行审核(在字段上:
@CreatedDate
@CreatedBy
@LastModifiedDate
@LastModifiedBy
)。当由Hibernate执行时,您应该调试delete语句的结果(是否删除了任何行)。我建议在调查时将org.hibernate日志级别设置为跟踪。我不认为事务没有提交,我宁愿说子查询中的where子句没有选择任何行(可能参数没有被Spring数据或Hibernate正确绑定)。我添加了
org.Hibernate
/
org.springframework.transaction
日志级别到
TRACE
。正如它所说的,事务已提交,但相关行未被删除。我的第一个想法是您所说的:子查询不选择任何行。这就是为什么我手动测试,但我成功地获得了行。如何查看参数是否未正确绑定?第二个选项:事务以静默方式结束/数据库中没有更改。是否对删除的实体进行版本控制?也就是说,actaul SQL是否在where子句中包含版本比较?否,实体没有版本控制,但它们通过使用
@EntityListeners
进行审核(在字段上:
@CreatedDate
@CreatedBy
@LastModifiedDate
@LastModifiedBy
)。当由Hibernate执行时,您应该调试delete语句的结果(是否删除了任何行)。我建议在调查时将org.hibernate日志级别设置为跟踪。我不认为事务没有提交,我宁愿说子查询中的where子句没有选择任何行(可能参数没有被Spring数据或Hibernate正确绑定)。我添加了
org.Hibernate
/
org.springframework.transaction
日志级别到
TRACE
。正如它所说的,事务已提交,但相关行未被删除。我的第一个想法是您所说的:子查询不选择任何行。这就是为什么我手动测试,但我成功地获得了行。如何查看参数是否未正确绑定?