0
@Antoniossss休眠更新子表而不是將記錄追加到子表
記錄正在插入到Wslog表中,但正在爲Emp錯誤。它也試圖插入對象wslog。
insert into wslog (totrecords, logid) values (?, ?)
insert into emp (sid, logid, **wslog**, eid, ename) values (?, ?, ?, ?, ?, ?, ?)
WsLog(主)
@Column(name = "logid") //has sequence
private long logid;
@Column(name = "totrecords")
private long totrecords;
@OneToMany(mappedBy="wslog")
private List<Emps> emplist;
EMPS(兒童)
@Id
@Column(name = "sid") //has sequence
private long sid;
@Column(name = "logid")
private long logid;
@Column(name = "eid")
private Long eid;
@Column(name = "ename")
private String ename;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "logid")
private Wslog wslog;
Repositiory
public interface WsLogRepository extends CrudRepository<WsLog, Long> {
}
服務實現
my.domain.client.model.Wslog wsLog = new Wslog();
wsLog.setTotrecords(getTotrecords());
List<my.domain.client.model.Employees> empList = new ArrayList<my.domain.client.model.Employees>();
for (my.domain.client.model.Employees emp : getEmployees()) {
my.domain.client.model.Employees emps = new Employees();
emps.setID(getEid());
emps.setEname(getEname());
emps.setLog(wsLog);
empList.add(emps);
}
wsLog.setEmployees(empList);
wsLogRepository.save(wsLog);
哪一列是emp表中的主鍵? – FuSsA
爲什麼你會設置'LogId'保證'Log'對象是另一個神祕的 – Antoniossss