简体   繁体   中英

bidirectional many-to-many in grails

I have two domain classes User and Group

the User can have multiple groups, and group can handle multiple users.

in JPA I used @ManyToMany with join table to achieve the behavior to update any of user or group without cascading delete. (so there are no owner for group or user)

is it possible to do with grails mapping?

Grails supports many-to-many relationships using the static hasMany property on both the User and Group domain classes. This is explained in the documentation here using many-to-many Books to Authors.

I have read, however, that there are downsides to having GORM manage the relationship. For example, Burt Beckwith explains here how adding a User to a Group (in your case) would cause GORM to unnecessarily load all the Users assigned to the Group. He goes on to explain managing the relationship using a separate domain class, UserRole in this example . You can use this last example as a guide and just replace references to Role with your Group class.

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