Jason Nichols
Jason Nichols

Reputation: 11753

Using JPA Annotations and Map<String,String> with a varchar length

I've got an entity that contains the following member attributes:

@Id
protected String id;

@ElementCollection(targetClass = String.class)
@MapKeyClass(String.class)      
protected Map<String, String> data = new HashMap<String,String>();

This maps to two tables, an ENTITY table, and an ENTITY_DATA table which contains a row for each element in the HashMap. It maps the values in the HashMap as VARCHAR(256) and I need it to be VARCHAR(1024). Can this be done? I cannot find anything in the ElementCollection or MapKeyClass annotations that would allow for this.

Upvotes: 3

Views: 2014

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42114

Because, as you say, problem is with values, it goes as with columns in general. Just add following annotation to the field.

@Column(columnDefinition = "varchar(1024)")

With JPA 2.0 you can do same also to field where key of the map is persisted with MapKeyColumn annotation:

@MapKeyColumn(columnDefinition = "varchar(1024)")

Upvotes: 6

Related Questions