Grails supports the mapping of basic collection types, for example:
static hasMany = [nicknames: String]
So what exactly is the difference between doing the above vs just adding an array (or list) of type String to the domain class – i.e.
List<String> nicknames
The difference is that with just:
Grails doesn’t know that you actually want that mapped (via Hibernate). Grails uses the
static hasManyto tell Hibernate how to work without a need for Hibernate mapping files.Technically, you don’t need to define the
List<String>. You only need thehasMany. This will default in aSet<String>. If you require an indexed list, then keepingList<String>along with thehasManyis fine as well.