仅部分转换回滚

时间:2018-06-07 10:32:03

标签: java spring hibernate transactions

当我执行此代码时,订单对象仍保留在DB的末尾,其中标签是test。因此,对象的更改将被回滚,而不是创建。我的期望是,在调用

之后,DB不包含任何订单或聊天频道条目
@Autowired
private OrderRepository orderRepository;

@Autowired
private ChatChannelRepository chatChannelRepository;

@RequestMapping(value = "/order/price", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Transactional
public double calculatePrice() throws CustomException {

    Order order = new Order();
    order.setLabel("Test");

    orderRepository.save(order);

    ChatChannel channel = new ChatChannel();
    channel.setOrder(order);

    chatChannelRepository.save(channel);

    order.setLabel("Test2");

    orderRepository.save(order);


    throw new RuntimeException("Test");
}



   @Transactional
 public interface ChatChannelRepository extends 
CrudRepository<ChatChannel, Long> {

public ChatChannel findById(long id);
}



@Transactional
public interface OrderRepository extends CrudRepository<Order, Long> 
{
public Order findById(long id);

public List<Order> findByBudgetIn(List<Budget> budgets);

public List<Order> findByBudgetInAndCurrentChainPosPhaseEquals(List<Budget> budgets, Phase phase);

public List<Order> findByProcessors(User currentUser);

}

0 个答案:

没有答案