Currently I have a Grails domain class with a HashMap of strings (HashMap metadata = new HashMap().
Everything is working fine with database persistence on creation (stored as BLOB by the way), start-up, shutdown, etc…
I have a nasty feeling that this is not okay for some reason, if that is the case why? if not, then never mind.
Versions etc Grails 2.0, Groovy 1.8, Java 1.6, Tomcat 6 MySQL 5.latest
I would say that this is probably not the best practice, since you never really know how this list of strings may grow in the future.
A simple example might be that in the future, you want to know when a particular field was added, which means you would have to change your entire domain model and move the hashmap out into child domains.
From experience, it might be easier to model this as a child element with name and value properties.
This also makes it easier to write queries against this hashmap, so if you wanted to find elements that have the key ‘blah’, you can use the dynamic finder and related querying mechanisms.