![](/img/trans.png)
[英]insert record with JPA having a field as an foreign key to another table
[英]Insert a record into foreign table in JPA
我有數據庫表中的實體,例如:
你看他們的關系是一個一對多的IDDot以點是標識列。 MaSoDuThuong中的IDMS是一個身份列。 通常,我可以將一條記錄插入到兩個表中,但是在另一頁中,當我知道IDDot的值時,需要在MaSoDuThuong表中插入一條記錄。 請幫我做!
Dot dot = entityManager.getReference(Dot.class, dotId);
MaSoDuThuong m = new MaSoDuThuong();
m.setDot(dot);
em.persist(m);
就如此容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.