[hibernate-issues] [Hibernate-JIRA] Commented: (JPA-11) @Lob annotation applies to both key and value of Map

Panayiotis Karabassis (JIRA) noreply at atlassian.com
Fri Jan 28 06:20:05 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/JPA-11?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39783#action_39783 ] 

Panayiotis Karabassis commented on JPA-11:
------------------------------------------

Sorry, the source code got mangled. Here it is again without the quote:

@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
} 

> @Lob annotation applies to both key and value of Map
> ----------------------------------------------------
>
>                 Key: JPA-11
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/JPA-11
>             Project: Java Persistence API
>          Issue Type: Bug
>         Environment: Hibermate 3.6.0.Final
> MySQL
>            Reporter: Panayiotis Karabassis
>
> 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:
> {quote}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.{quote}
> To reproduce:
> {quote}@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
> }{quote}
> This produces the following error during schema creation:
> {quote}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{quote}
> Workarounds include defining column type with @MapKeyColumn(columnDefinition = "...") or using @Embeddable as a wrapper for values. (thanks to axtavt and Sean Patrick Floyd)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list