Search code examples
jpawebsphere

JPA Array index out of range


I am using JPA in my WAS 6.1. I try to execute this line:

@Entity
@Table(name="some_Table")
@NamedQueries({
@NamedQuery(name="getAllAccountTypeService",
query="SELECT a FROM AccountTypeServiceAssoc a " +
"WHERE a.delete.deletedDate IS NULL ")

.....

Query query = em.createNamedQuery("getAllAccountTypeService");  
return query.getResultList();

I get this on my SystemOut.log: org.apache.openjpa.persistence.PersistenceException: Array index out of range: 48

Where is the array in the above code that is going out of range? The error comes in this Line #100:

EnumValueHandler.java(This is a jpa class)

 public Object toObjectValue(ValueMapping vm, Object val) {
   97           if (val == null)
   98               return null;
   99           if (_ordinal)
  100               return _vals[((Number) val).intValue()];
  101           return Enum.valueOf(vm.getType(), (String) val);
  102       }

I cannot figure out what is _vals and what is val Thank you for your help.

EDIT: Thank you for the answer. The column is indeed mapped to an ordinal like this:

@Column(name="SVC_ID") @Enumerated(EnumType.ORDINAL) protected ServiceType service;

But where do we set the range of the Ordinal? That makes 48 outside the range.


Solution

  • One of the fields of the entities that are loaded is an enum, mapped as ordinal.

    This means that the ordinal of the enum is stored in the database, and is used when loading the object to find the corresponding enm instance.

    And instead of one of the valid ordinals (from 0 to 4 if there are 5 values for that enum), the cell in the database contains the value 48 (which would require en enum with at least 49 instances).

    In short, the data in the database is invalid, or should not be mapped with an enum.