我有两个实体,Document和BodyElement,并试图用Hibernate 4.2来保持它们. mtdt_t正确填充,但mtdt_body_t表中的外键docid为NULL.
我看到hibernate试图在没有docid值的情况下插入.插入mtdt_body_t values()
@Entity
@Table(name = "mtdt_t")
public class Document implements Serializable {
@Id
@Column(name = "docid", unique = true, nullable = false)
private String docid;
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OrderColumn
@JoinColumn(name = "docid", nullable = false)
private BodyElement bodyElement;
public String getDocid() {
return docid;
}
public void setDocid(String docid) {
this.docid = docid;
}
public BodyElement getBodyElement() {
return bodyElement;
}
public void setBodyElement(BodyElement bodyElement) {
this.bodyElement = bodyElement;
}
}
@Entity
@Table(name = "mtdt_body_t")
public class BodyElement implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne
@JoinColumn(name = "docid", insertable = false, updatable = false, nullable = false)
private Document document;
public BodyElement() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
}
我离开了另一个领域.在我有的文件中,
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OrderColumn
@JoinColumn(name = "docid", nullable = false)
@XmlPath("head/meta/kb:keywords/kb:keyword")
private Set keywords;
在Keyword类中,我将外键映射为,
@ManyToOne
@JoinColumn(name = "docid", insertable = false, updatable = false, nullable = false)
@XmlTransient
private Document document;
并且该docid字段永远不会为NULL.
与@OneToMany相比,@ OneToOne Mapping有什么特别之处吗?我只是在@OneToOne字段上模仿我为@OneToMany做的事情.
谢谢