简体   繁体   中英

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. The IDMS in MaSoDuThuong is an identity column. 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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