這是我的 「頭」 實體:@OneToMany關係: 「一」 ID不持久
@Entity
@Table(name = "documenti")
@Inheritance(strategy=InheritanceType.JOINED)
public class Documento implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@OneToMany(
mappedBy="testataDocumento",
cascade=CascadeType.ALL,
fetch=FetchType.LAZY
)
private Set<RigaDocumento> righe= new HashSet<RigaDocumento>();
//...
}
而這些都是 「行」:
@Entity
@Table(name="righe_documenti")
public class RigaDocumento implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@ManyToOne
private Documento testataDocumento;
//...
}
嗯,我有一個共同的情況:
Documento d = new Documento();
// various Documento settings
List<RigaDocumento> rows;
// creation of rows
d.setRighe(rows);
然後我堅持d。
頁眉堅持正確和行太多,但在各行記錄
的「testataDocumento_id」字段(關鍵關係的「一」方)爲NULL。
我必須做:
row.setTestataDocumento(d);
?
爲什麼?