这是我的“标题”实体:
@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);
?
为什么??