Spring Data JPA事务

时间:2015-08-25 12:29:21

标签: java jpa spring-data spring-data-jpa

我有三个相互关联的类,如

  • Product -oneToMany-> ProductRevision

  • ProductRevision -oneToMany-> ProductDateVarient

我对所有这些实体使用了以下cascadeType

产品:

@OneToMany(mappedBy = "product", fetch = FetchType.EAGER, 
        cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
private Set<ProductRevision> productRevisions;

产品修订:

@OneToMany(mappedBy = "productRevision", fetch = FetchType.EAGER, 
        cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
private Set<ProductDateVariant> productDateVariants ;
//save Product data with Populated values for ProductRevision and  ProductDateVarient
productRepository.save(product);

当我尝试使用Product的无效数据保存ProductDateVarient数据时,它会为其提供例外但会保存ProductRevision的数据。我认为它应该是事务,以便在发生异常时,ProductRevision数据不会被保存。我错过了什么?

0 个答案:

没有答案