为什么控制器在集合流

时间:2017-02-17 14:46:38

标签: spring hibernate spring-boot transactional

我不知道为什么当我在控制器中更改实体时,它会保存在数据库中。看起来控制器有一个事务。当我在for循环中设置属性时,它没有保存在数据库中。

我的弹簧控制器

  @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;
        }

    }

和存储库

 @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();
        }
    }

1 个答案:

答案 0 :(得分:1)

当满足以下条件时,Spring Boot将自动注册if ((_player.rate != 0) && (_player.error == nil)) // player is playing { AVAssetTrack *track = [[_player.currentItem.asset tracksWithMediaType:AVMediaTypeVideo] firstObject]; if (track != nil) // not HLS { CGSize naturalSize = [track naturalSize]; naturalSize = CGSizeApplyAffineTransform(naturalSize, track.preferredTransform); _videoWidth = (NSInteger) naturalSize.width; _videoHeight = (NSInteger) naturalSize.height; } else // HLS!! { CMTime currentTime = _player.currentItem.currentTime; CVPixelBufferRef buffer = [_videoOutput copyPixelBufferForItemTime:currentTime itemTimeForDisplay:nil]; _videoWidth = CVPixelBufferGetWidth(buffer); _videoHeight = CVPixelBufferGetHeight(buffer); } } NSLog(@"Resolution : %ld x %ld", _videoWidth, _videoHeight);

  • 您有一个网络应用程序
  • 您使用JPA

在您的情况下,这两个条件都是正确的。此拦截器使实体管理器在整个请求期间保持打开状态。自动配置发生在类OpenEntityManagerInViewInterceptor中。

要禁用该行为,您需要配置以下属性:

JpaBaseConfiguration