Spring 为什么控制器在收集流时有事务
我不知道为什么当我在控制器中更改实体时,它会保存在数据库中。看起来控制器有一个事务。当我在for循环中设置属性时,它不会保存在数据库中 我的弹簧控制器Spring 为什么控制器在收集流时有事务,spring,hibernate,spring-boot,transactional,Spring,Hibernate,Spring Boot,Transactional,我不知道为什么当我在控制器中更改实体时,它会保存在数据库中。看起来控制器有一个事务。当我在for循环中设置属性时,它不会保存在数据库中 我的弹簧控制器 @RestController public class CartController { @Autowired DeliveryTypeRepository deliveryTypeRepository; @GetMapping("/cartStepTwoAction")
@RestController
public class CartController {
@Autowired
DeliveryTypeRepository deliveryTypeRepository;
@GetMapping("/cartStepTwoAction")
public ModelAndView cartStepTwoAction() {
List<DeliveryType> dtList = deliveryTypeRepository.findAll();
dtList.stream().forEach(x -> x.setPriceBrutto(new BigDecimal(44)));
// why dirty checking save change ?
...
ModelAndView model = new ModelAndView();
return model;
}
}
@RestController
公共类控制器{
@自动连线
DeliveryTypeRepository DeliveryTypeRepository;
@GetMapping(“/cartStepTwoAction”)
公共模型和视图cartStepTwoAction(){
List dtList=deliveryTypeRepository.findAll();
dtList.stream().forEach(x->x.setPriceBrutto(新的BigDecimal(44));
//为什么脏检查保存更改?
...
ModelAndView模型=新的ModelAndView();
收益模型;
}
}
,以及储存库
@Repository
public class DeliveryTypeRepositoryImpl implements DeliveryTypeRepository {
@PersistenceContext
EntityManager em;
@Override
public List<DeliveryType> findAll() {
String sql = "SELECT e FROM DeliveryType e";
Query query = em.createQuery(sql);
return query.getResultList();
}
}
@存储库
公共类DeliveryTypeRepositoryImpl实现DeliveryTypeRepository{
@持久上下文
实体管理器;
@凌驾
公共列表findAll(){
String sql=“从DeliveryType e中选择e”;
Query Query=em.createQuery(sql);
返回query.getResultList();
}
}
当下列条件为真时,Spring Boot将自动注册一个OpenEntityManagerViewInterceptor
:
- 您有一个web应用程序
- 你使用JPA
JpaBaseConfiguration
中
要禁用该行为,需要配置以下属性:
spring.jpa.open-in-view=false
您是否在自动配置或自定义配置中定义了
OpenEntityManagerViewFilter
?否我没有定义OpenEntityManagerViewFilter