How to configure DB restrictions / mapping for Map in domain grails class

The following grails domain class:

class MyClass { Map myMap } 

Now for myMap grails automatically creates a new table for elements on the map. However, if I add elements that are too long (for example, 1024 characters), I get a DB error.

Can I somehow tell grails to make the corresponding column in the myMap table large enough to allow large rows, or do I need to do this manually in the database?

I have already tried

 static constraints = { myMap(maxSize:1024) } 

which does not work (as expected, since maxSize should refer to the values ​​of the map and not to the map itself).

If not through restrictions, there may be a way to do this through

 static mapping { ... } 

?

+4
source share
2 answers

The alternative approach that I used successfully was to bring the map to a collection of a co-author domain class.

 class DynaProperty { String name String value static belongsTo = MyClass static constraints = { value(maxSize:4000) //Or whatever number is appropriate } } 

And then in MyClass:

 class MyClass { static hasMany = [dynaProperties:DynaProperty] } 

This is almost a map, and it gives you the ability to use dynamic crawlers to select a single record.

+5
source

what are you trying to accomplish? Is there always the same number of things on the map? If so, you must define these properties in your class.

You can see the problem with your current approach - there is no way to find out what can be on the map before the execution time, so how can the rake create columns for it? Im surprised it even worked to start with ...

0
source

Source: https://habr.com/ru/post/1315523/


All Articles