我有以下表格:
(所有字段都不可为空)
以下的hibernate映射:
class Product {
@Id
private Integer id;
@OneToMany(mappedBy="product")
@Cascade({CascadeType.ALL})
private Set<ProductProperties> productProperties = new HashSet<ProductProperties)(0);
(...)
}
当我通过在“productProperties”字段中添加或删除行来更新产品类时,行会在PRODUCT_PROPERTIES表中正确更新。
问题是当“productProperties”为null或为空时,Hibernate会抛出ConstraintViolationException。
由于我有时需要“productProperties”为空,是否有适当的解决方案来处理这个问题(类似@ZeroToMany注释)?
答案 0 :(得分:0)
答案由Dev Blanked在评论中给出。 这是解决方案:
@OneToMany(mappedBy="foo", orphanRemoval=true)