![](/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.