如何在没有事务的情况下使用 Spring-Jpa 中的 JpaSpecificationExecutor
How can I Use JpaSpecificationExecutor from Spring-Jpa without transaction
enter image description here当我使用JpaSpecificationExecutor做findAll时,我找到了
自动添加交易,从 sql 开始到
设置自动提交 = 0;
而且我不想要它。
我测试了 JpaRepository,做同样的事情 select sql 但它没有与
设置自动提交 = 0;
但是 JpaSpecificationExecutor 有。
然后我断点它,发现有一个 PROXY 做那个添加事务的事情,但我不知道如何禁用它。
我确实设置了 defaultAutoCommit: true
我也设置了
datasource:
tomcat:
default-auto-commit: true
dbcp2:
default-auto-commit: true
连接池已经默认AutoCommit=true
没用
所以我责怪 JpaSpecificationExecutor
@Repository
public interface GameRepository extends JpaRepository<GameEntity, Integer>, JpaSpecificationExecutor<GameEntity> {
List<GameEntity> findByName(String name);
}
public List<GameEntity> search(HttpServletRequest request) {
return mGameRepository.findAll(searchAction(request), new Sort(Sort.Direction.DESC, "id"));
}
break point screen cut
事实证明,所有 CRUD 方法(CrudRepository 方法)默认都标记为事务性的。
但是如何取消标记呢?
enter image description here当我使用JpaSpecificationExecutor做findAll时,我找到了 自动添加交易,从 sql 开始到
设置自动提交 = 0;
而且我不想要它。
我测试了 JpaRepository,做同样的事情 select sql 但它没有与 设置自动提交 = 0;
但是 JpaSpecificationExecutor 有。
然后我断点它,发现有一个 PROXY 做那个添加事务的事情,但我不知道如何禁用它。
我确实设置了 defaultAutoCommit: true
我也设置了
datasource:
tomcat:
default-auto-commit: true
dbcp2:
default-auto-commit: true
连接池已经默认AutoCommit=true
没用
所以我责怪 JpaSpecificationExecutor
@Repository
public interface GameRepository extends JpaRepository<GameEntity, Integer>, JpaSpecificationExecutor<GameEntity> {
List<GameEntity> findByName(String name);
}
public List<GameEntity> search(HttpServletRequest request) {
return mGameRepository.findAll(searchAction(request), new Sort(Sort.Direction.DESC, "id"));
}
break point screen cut
事实证明,所有 CRUD 方法(CrudRepository 方法)默认都标记为事务性的。
但是如何取消标记呢?