Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
用户表
用户名 pk fname lname
群主
组名 pk 用户名 pk, fk
我想在 GroupMaster 中插入数据,但我的问题是它有复合主键
如何通过实体管理器对象在表中插入数据?
这可以通过@Embeddable注释来完成。设置一个包含主键值的新类——在本例中,一个带有GroupName和UserName字段的类,用 注释该类,然后在需要主键的 中@Embeddable存储一个实例。@Entity
@Embeddable
GroupName
UserName
@Entity
看看下面的例子:
在 Hibernate 中使用复合键