Spring repo上的java@Transaction只读和另一个repo上的save
我已经实现了以下代码部分:
public void computeAllBilling() {
orderRepository.getAll().parallel().forEach(ordreEntity -> {
Billing billing = computedBilling(orderEntity);
billingRepository.save(billing);
entityManager.detach(ordreEntity);
});
}
public interface BillingRepository extends JpaRepository<BillingEntity, String> {
@QueryHints(value = {
@QueryHint(name = org.hibernate.jpa.QueryHints.HINT_FETCH_SIZE, value = "1"),
@QueryHint(name = org.hibernate.jpa.QueryHints.HINT_CACHEABLE, value = "false"),
@QueryHint(name = org.hibernate.jpa.QueryHints.HINT_READONLY, value = "true")
})
@Query(value = "SELECT o.* FROM raw.ordre o", nativeQuery = true)
Stream<BillingEntity> getAll();
}
我需要快速地从一个表中读取数据,但在我们的业务处理中,我们需要在末尾保存账单(在读卡器发出一个订单后,必须保存账单)
但是在这个链接之后:https://www.geekyhacker.com/2019/03/26/high-performance-data-fetching-using-spring-data-jpa-stream/
最后,我需要保存到另一个存储库中,而不是读卡器存储库中。 有人知道要避免什么吗
“org.springframework.dao.InvalidDataAccessApiUsageException:您正在尝试执行流查询方法,但没有保持连接打开的周围事务,以便流可以实际使用。请确保使用流的代码使用@Transactional或任何其他方式声明(只读)事务。 "
求你了?非常感谢,并致以最良好的问候
阿德里安
共 (0) 个答案