I think I can answer these questions, however someone correct me if I'm wrong.
Composite keys aren't something that just Grails discourages. It's generally discouraged in table design as a whole. The biggest drawback to doing so is that it makes relationships with other tables more complex. It really doesn't have that much to do with Grails, rather database design in general.
My guess here is that because nothing references the UserRole table, it doesn't hurt. He could have used a primary key, then just created a unique key between user and role, but because no other domain references UserRole, why add the unnecessary field. If you don't override hashCode
or equals
, you won't be able to compare the domain.
Yes, the same rules apply in Grails 2, however Grails now supports Bags. This would provide the same benefits he outlined in that talk, without losing the Groovyness of the current Grails syntax. This is not the default so you would have to specify.
Code to set a collection as a Bag:
Collection books
static hasMany = [books: Book]