我有两个表加入一个映射表。不过,我遇到了一个空约束问题。下面是错误消息和两个映射。由于两者都是 manyTomany,我的假设是 many 可能没有,我怎样才能做到这样 product_id 或 category_id 都可以为空?
错误信息
Caused by: org.h2.jdbc.JdbcBatchUpdateException: NULL not allowed for column "PRODUCT_OPTION_ID"; SQL statement:
insert into ImageMapping (product_id, image_id) values (?, ?) [23502-168]
类别
@JoinTable(
name = "ImageMapping",
joinColumns = @JoinColumn(name = "category_id"),
inverseJoinColumns = @JoinColumn(name = "image_id")
)
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
private Set<Image> categoryImageId;
产品
@JoinTable(
name="ImageMapping",
joinColumns = @JoinColumn(name = "product_id"),
inverseJoinColumns = @JoinColumn(name = "image_id")
)
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
private Set<Image> productImageGroup;
产品选项
@JoinTable(
name="ImageMapping",
joinColumns = @JoinColumn(name = "product_option_id"),
inverseJoinColumns = @JoinColumn(name = "image_id")
)
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Image> productOptionImageGroup;