在grails document的5.5.2.5节中说
GORM supports the concept of composite identifiers (identifiers composed from 2 or more properties). It is not an approach we recommend, but is available to you if you need it
为什么不是一个好主意?我有以下表格定义:
User (Table)
Column: userId (Primary Key)
FriendMap
Composite Key Column: userId (foreign key from User) and friendId
这是一个坏主意吗?
最佳答案
对于用于多对多映射的联接表,这并不是一个坏主意,这就是您使用它的样子。
有许多反对使用复合键而不是使用单个数字递增ID字段的参数。它们主要涉及使更改和重构域变得更加复杂。
对于映射类,一个很好的例子是Burt的spring-security-core插件的mapping class between User and Role。
关于hibernate - 在GORM中使用复合键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4665295/