我有三个相互关联的类,如
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
数据不会被保存。我错过了什么?