标签:end 而在 iter action 源码 sim readonly serial 方法
一 点睛
Spring Data JPA对所有默认方法都开启了事务支持,且查询类事务默认启用readOnly=true属性。
二 SimpleJpaRepository缩减版源码
@Repository @Transactional(readOnly = true) public class SimpleJpaRepository<T, ID extends Serializable> implements JpaRepository<T, ID>, JpaSpecificationExecutor<T> { ...... @Transactional public void delete(ID id) { ...... } @Transactional public void delete(T entity) { ...... } @Transactional public void delete(Iterable<? extends T> entities) { ...... } @Transactional public void deleteInBatch(Iterable<T> entities) { ...... } @Transactional public void deleteAll() { ...... } @Transactional public void deleteAllInBatch() { ...... } public T findOne(ID id) { ...... } protected Map<String, Object> getQueryHints() { ...... } private JpaEntityGraph getEntityGraph() { ...... } @Override public T getOne(ID id) { ...... } public boolean exists(ID id) { ...... } public List<T> findAll() { ...... } public List<T> findAll(Iterable<ID> ids) { ...... } public List<T> findAll(Sort sort) { ...... } public Page<T> findAll(Pageable pageable) { ...... } public T findOne(Specification<T> spec) { ...... } public List<T> findAll(Specification<T> spec) { ...... } public Page<T> findAll(Specification<T> spec, Pageable pageable) { ...... } public List<T> findAll(Specification<T> spec, Sort sort) { ...... } public long count() { ...... } public long count(Specification<T> spec) { ...... } @Transactional public <S extends T> S save(S entity) { ...... } @Transactional public <S extends T> S saveAndFlush(S entity) { ...... } @Transactional public <S extends T> List<S> save(Iterable<S> entities) { ...... } ...... }
三 源码分析
从源码分析可以看出,SimpleJpaRepository在类级别定义了@Transactional(readOnly = true),而在和save、delete相关的操作重写了@Transactional属性,此时readOnly属性是false,其余查询操作readOnly仍然为true。
标签:end 而在 iter action 源码 sim readonly serial 方法
原文地址:https://www.cnblogs.com/zouhong/p/13289130.html