0 Replies Latest reply on May 26, 2008 3:42 AM by Swen Barth

    Unknown ordinal value for enum class

    Swen Barth Newbie

      Hi, I'm currently using JBoss 4.0.4GA with EJB3, MySQL 5.0 and mysql-connector-java-5.0.6

      I have a bean with an enumeration attribute:

       private ItemType type;
      
       @Column(name = "TYPE", nullable = false)
       public ItemType getType() {
       return type;
       }
      
       public void setType(ItemType type) {
       this.type = type;
       }
      


      The Enumeration is defined as follows:

      public enum ItemType {
       SERVICE, MATERIAL, SURCHARGE, PLANNED_WITHDRAWAL, ACTUAL_WITHDRAWAL, FREETEXT_TEMPLATE
      }
      


      This works fine most of the time. However, occasionally this very attribute is written to the DB with bogus values, and when retrieving the bean, I get the following error:

      java.lang.IllegalArgumentException: Unknown ordinal value for enum class xxx.xxx.xxx.xxx.enums.ItemType: -2147483644
      at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:88)
      at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:104)
      at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
      at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:1983)
      at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1372)
      at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1300)
      at org.hibernate.loader.Loader.getRow(Loader.java:1197)
      at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:569)
      at org.hibernate.loader.Loader.doQuery(Loader.java:689)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
      at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
      at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
      at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:541)
      at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
      at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1705)
      at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
      at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:755)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
      at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
      at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2821)
      at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:370)
      at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:351)
      at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:122)
      at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:178)
      at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
      at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:871)
      at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
      at org.hibernate.impl.SessionImpl.get(SessionImpl.java:801)
      at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:155)
      ...


      When I check directly in the DB, I find this strange value (-2147483644), so the exception is entirely correct.
      This problem is not reproducable, as I said the attribute is written correctly to the DB most of the time.

      Does anyone know how to approach this problem?