Mam dwa elementy: Document
i BodyElement
i próbuję je zachować przy użyciu Hibernuj 4.2. mtdt_t
zapełnia się poprawnie, ale klucz obcy docid
w tabeli mtdt_body_t
to NULL
.Pole klucza obcego puste w odwzorowaniu @OneToOne z Hibernate/JPA
Widzę, że hibernacja próbuje wstawić wartość bez wartości docid
. insert into 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;
}
}
Opuściłem inne pole. W Document
mam,
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OrderColumn
@JoinColumn(name = "docid", nullable = false)
@XmlPath("head/meta/kb:keywords/kb:keyword")
private Set<Keyword> keywords;
w klasie Keyword
Mam klucz obcy odwzorowaną jak
@ManyToOne
@JoinColumn(name = "docid", insertable = false, updatable = false, nullable = false)
@XmlTransient
private Document document;
i że docid
pole nigdy nie jest NULL
.
Czy jest coś szczególnego w mapowaniu @OneToOne
w porównaniu do @OneToMany
? Po prostu naśladowałem to, co zrobiłem dla @OneToMany
w polu @OneToOne
.
Dzięki
Podążyłem za przykładem mkyonga za pomocą 'mappedBy', ale nadal pozostawił on pole' docid'. Tym razem kolumna 'docid' nie była nawet obecna. – wsams