简体   繁体   中英

Unidirectional M:M in Grails GORM

Is it possible to have a Unidirectional M:M in Gorm?

eg I have a Person object and I have TravelDestionion object.

A person can have been to many travel destination and some of these travel destinations have of course had many people. But, I never want to navigate from TravelDestination to Person.

Any tips?

You can technically just not access the other side, but Grails is too helpful in this regard. For example when you want to associate a new TravelDestination instance with a Person , you add it to the person's destinations collection (or whatever you named it). But to ensure that both sides are in sync with what the database will look like after calling save , Grails adds the Person to the TravelDestination 's persons collection.

This can obviously be very expensive, eg with a User <-> Role relationship where 1,000,000 users have ROLE_USER, and one more gets that role, and that user becomes element #1,000,001 in the role's users collection, which gets loaded into memory by Hibernate to ensure uniqueness.

Check out this presentation where I discuss this and provide some performant options for reconfiguring the relationship without the potentially huge overhead of using collections to represent 1-many and many-many in GORM: http://www.infoq.com/presentations/GORM-Performance

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