简体   繁体   English

在JPA中将记录插入到外部表中

[英]Insert a record into foreign table in JPA

I have entities from tables in database such as: 我有数据库表中的实体,例如: 在此处输入图片说明

You see their relationship is one-to-many The IDDot in Dot is an identity column. 你看他们的关系是一个一对多的IDDot是标识列。 The IDMS in MaSoDuThuong is an identity column. MaSoDuThuong中IDMS是一个身份列。 In normally, i can insert one record into two tables but in other page I need to insert a record into MaSoDuThuong table when i know the value of IDDot . 通常,我可以将一条记录插入到两个表中,但是在另一页中,当我知道IDDot的值时,需要在MaSoDuThuong表中插入一条记录。 Pls help me do! 请帮我做!

Dot dot = entityManager.getReference(Dot.class, dotId);
MaSoDuThuong m = new MaSoDuThuong();
m.setDot(dot);
em.persist(m);

As simple as that. 就如此容易。

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

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