简体   繁体   English

持久收藏JPA

[英]Persist Collection JPA

I have a bean 我有一个豆

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;

when I put on my db record is created on the table Verbali but not records on the @OneToMany. 当我放入数据库时​​,在表Verbali上创建记录,但在@OneToMany上没有记录。 where wrong??? 哪里错了???

When I have this type of rellations first I save the main class (in this case Verbali) and then save the childrens adding this new record to it. 当我有这种类型的称呼时,首先保存主类(在本例中为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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM