我有一个豆子
public class Verbali implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ID")
private Long id;
@JoinColumn(name = "ID_UTENTE", referencedColumnName = "ID")
@ManyToOne(optional = false)
private Utenti idUtente;
@OneToMany(mappedBy = "idVerbale")
private Collection<PresenzeVerbali> presenzeVerbaliCollection;
@OneToMany(mappedBy = "idVerbale")
private Collection<OrdineDelGiorno> ordineDelGiornoCollection;
当我把我的数据库记录创建在Verbali表上而不是@OneToMany上的记录。 哪里错了???
答案 0 :(得分:0)
当我有这种类型的翻译时,我首先保存主要类(在本例中为Verbali),然后保存孩子们将新记录添加到其中。
Verbali verbali = new Verbali();
verbali.setIdUtente(retrieveUtente());
verbali = verbaliPersistence.save(verbali);
for(somestuff){
PresenzeVerbali pv = new PresenzeVerbali();
pv.setVerbali = verbali;
presenzeVerballiPersistence.save(pv);
//same with other collections
}