java - JPA Map<String,String> restriction on map value length? -


@entity @table(name="foo") public class fooentity {     @id     private string name;     ...     @elementcollection(fetch=fetchtype.eager)     private map<string, string> properties = new hashmap<>();     ... } 

i've got jpa entity similar what's shown above. when running above "properties" table default maximum length map value column of 255 characters. how change length restriction on map value, if wanted support lengths of (say) 64k value (not key)?

you can use following mapping:

@entity @table public class foo {     // id, other properties, ...      @elementcollection     @mapkeycolumn(name="key", length=100)     @column(name="value", length=512)     @collectiontable(name="properties", joincolumns=@joincolumn(name="foo_id"))     private map<string, string> properties; } 

the interesting part @column annotation allows customize mapping of value column.

this mapping result in following ddl when run schema export:

create table properties (     foo_id int8 not null,     value varchar(512),     key varchar(100) not null,     primary key (user_id, key) ); 

Comments