我Content有一个 Map Footnote,并且Footnote有一content_id列是返回的外键Content。不幸的是Content,使用footnoteMap包含 a保存我Footnote会引发以下错误:
ERROR: Cannot insert the value NULL into column 'content_id', table 'CMT_DEV.dbo.footnote'; column does not allow nulls. INSERT fails.
SEVERE: org.springframework.dao.DataIntegrityViolationException: Cannot insert the value NULL into column 'content_id', table 'CMT_DEV.dbo.footnote'; column does not allow nulls. INSERT fails.; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Cannot insert the value NULL into column 'content_id', table 'CMT_DEV.dbo.footnote'; column does not allow nulls. INSERT fails.
我必须缺少使这项工作所需的注释,但我无法弄清楚它是什么。
这是我的 JPA 映射:
public class Content implements EntityModel, Serializable {
@OneToMany(mappedBy="contentId", cascade=CascadeType.ALL)
@MapKey(name="number")
@OrderBy("number ASC")
private Map<Integer, Footnote> footnoteMap;
....
}
public class Footnote implements EntityModel, Serializable {
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "content_id", referencedColumnName= "id")
private Content contentId;
....
}
* 更新 *
请记住,在Footnote添加 a 时,内容项尚未保存。