@Lob annotation applies to both key and value of Map

Description

When using the @Lob annotation on a java.util.Map I find that both the value and key of the Map are mapped to a BLOB. This is in violation of the JPA 2.0 specification which states:

The Lob annotation may be used in conjunction with the Basic annotation or with the ElementCollection[100] annotation when the element collection value is of basic type.
...

[100] If the element collection is a Map, this applies to the map value.

To reproduce:

@Entity
public class Entry
{
@Id @GeneratedValue
private long identifier;

@ElementCollection
@Column(nullable = false)
private Map<String, String> titles;

@ElementCollection
@Column(nullable = false)
@Lob
private Map<String, String> contents;

// Getters and setters, other fields and methods
}

This produces the following error during schema creation:

Unsuccessful: create table myblog.Entry_contents (Entry_identifier bigint not null, contents longtext not null, contents_KEY longtext, primary key (Entry_identifier, contents_KEY)) type=InnoDB
BLOB/TEXT column 'contents_KEY' used in key specification without a key length

Workarounds include defining column type with @MapKeyColumn(columnDefinition = "...") or using @Embeddable as a wrapper for values. (thanks to axtavt and Sean Patrick Floyd)

Environment

Hibermate 3.6.0.Final
MySQL

Assignee

Unassigned

Reporter

Panayiotis Karabassis

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Major
Configure