uknownot
uknownot

Reputation: 23

Grails mapping basic collection types

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 

Upvotes: 2

Views: 695

Answers (1)

Gregg
Gregg

Reputation: 35864

The difference is that with just:

List<String> nicknames

Grails doesn't know that you actually want that mapped (via Hibernate). Grails uses the static hasMany to 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 the hasMany. This will default in a Set<String>. If you require an indexed list, then keeping List<String> along with the hasMany is fine as well.

Upvotes: 4

Related Questions