[hibernate-issues] [Hibernate-JIRA] Created: (ANN-808) @Enumerated(ORDINAL) does not work on VARCHAR columns

Eduardo Costa (JIRA) noreply at atlassian.com
Tue Mar 17 10:35:38 EDT 2009


@Enumerated(ORDINAL) does not work on VARCHAR columns
-----------------------------------------------------

                 Key: ANN-808
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-808
             Project: Hibernate Annotations
          Issue Type: Bug
    Affects Versions: 3.3.1.GA
         Environment: Tested on Postgres, but the problem should be reproductible on any DB vendor
            Reporter: Eduardo Costa


Copied from http://forum.hibernate.org/viewtopic.php?t=995698:

==========
Suppose I have this enum:

public enum Status { OK, NOK, NOT_APPLICABLE }

And this property:

@Column(name = "status")
@Enumerated(EnumType.ORDINAL)
private Status status;

And this table (legacy, CANNOT be changed):

CREATE TABLE tb_xxx (
  id bigint NOT NULL,
  status character varying(1) NOT NULL,
)

It leads to this exception:

java.lang.IllegalArgumentException: No enum const class mypkg.Status.1
   java.lang.Enum.valueOf(Enum.java:196)
   org.hibernate.type.EnumType.nullSafeGet(EnumType.java:110)

Taking a look at EnumType.java, it is clear that Hibernate imposes ordinal stored as number and name stored as varchar.
=========

IMHO, this is a "specification gap": JPA does not consider what to do if I'm trying to map a legacy enumerated value. Since I'm defining @Enumerated as "ordinal" and I have "0", "1", "2" on my database, I believe Hibernate should consider what I'm defining, not what an ancient DBA defined. Otherwise, I can't map this using only Hibernate Annotations/JPA (BTW, this code works with TopLink, only changing JPA provider on persistence.xml)

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