|
Hi, option 5 breaks database 1st normal form.
I think separating the tables is a good option. Maybe it's a good idea to set the table name to something that denotes that is a table of datavalues and not a mapping from a domain class, something like: string_collection_1234 or string_map_3214, and the mapping table of the domain class that has this attribute (collection or map of strings) reference to those table names, I'm only thinking about it, I dont know very much about how hibernate works. Looks like Hibernate supports collections of basic types by creating a dedicated table. The mapping looks like this:
<set name="names" table="person_names"> <key column="person_id"/> <element column="person_name" type="string"/> </set> More info here: http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html#collections-ofvalues Hi, I am also trying to do this, like this:
class NetworkOperator{ String name HashMap otherNames = new HashMap() static hasMany = [otherNames:String] } I would expect this to work in a dedicated table, I will probably use Peter's Hibernate manual mapping for now. It would be very nice if grails could do this on it's own... Thanks! GORM now supports basic collection types using a join table:
class Person {
static hasMany = [nicknames:String]
}
Grails will map a new join table called "person_nicknames":
You can change the mapping using the joinTable argument: class Person {
static hasMany = [nicknames:String]
static mapping = {
hasMany joinTable:[name:'bunch_o_nicknames', key:'person_id', column:'nickname', type:"text"]
}
}
minor edit made to description of fix
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Option 1:
Use JDBC ARRAY type.
Option 2:
Use Java serialization to store the whole collection in a column of byte array. (BLOB or VARBINARY or LONGVARBINARY).
Option 3:
Use XML serialization to store the whole collection in a column of VARCHAR or LONGVARCHAR.
Option 4:
Store the collection in a separate table.
Option 5:
Hacks, such as comma-delimited String... What about having a comma in a String element? What about various types within one array?
As there are workarounds, I propose to lower the priority to 'Minor'.