Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] enum access cast issue

No, I have a list of enums, not strings.  I'm not using the @Enumerated
annotation, but the docs say the default is to store them as ordinals, so I
assume that should be what it's doing (based on JPA 2.0 docs).  In three of
four cases, this happens correctly and it reads the objects as enums, but in
one case, it gets confused and thinks the objects are strings.  It then
complains that it can't convert them to enums.

The list in question is part of a Predicate object.  The Predicate object is
included in a Clause object and I have four different types of clauses that
I use.  When I access three of the four clause types, everything is fine,
but one clause type causes it to fail and I have no idea what could be
different.  The clause object is the same but the function is distinguished
by another enum value stored in the clause.

It doesn't make any sense to me because it's the exact same lines of code
that work in one case but not in another.  How can that be?  There is
nothing different about the way I treat and access a Predicate object based
on the type of clause and it goes through exactly the same code path.  

Even beyond that, in the logs I included which show one good case and one
failed case, the type of clause is the same.  In the first case that
succeeds, I am retrieving the value by starting with the clause object, and
in the case that fails, I am retrieving the value by starting with another
object that includes the clause which then of course includes the predicate
object.  The reason I say that three out of four clause types work is
because with the other three types, I can include them in other objects
nested as much as I need and the predicate values and verbForms are always
handled correctly.

You can see in the log I included that in the first case (starting from the
clause object), the object is correctly understood as a VerbForm enum with
the value of ED, and in the failure case (starting from another object that
includes the clause object), the value is still ED, but the system thinks it
needs to convert from a string to an enum.  I'm simply accessing it with
verbForms.get(indexValue) where the index value is zero in both cases.

I'm really baffled.  Any help or suggestions would be much appreciated! 


(BTW, Sorry if the included messages are a little weird.  My browser doesn't
seem to be handling them well.)

James Sutherland wrote:
> So you have a List of basic Enum types, stored as String (VARCHAR) in the
> database, and in some cases your object's values are the correct Enums,
> and in another case (for the same class/attribute) there are Strings in
> the List not the Enums, correct?
> That is odd, it seems the Converter on the DirectCollectionMapping is not
> be utilized in your exception case.  What is different about the case
> where it works and doesn't?  How do you read this object?
> drrevis wrote:
>> Hi,
>> I'm using Glassfish v3 w/EclipseLink and have an entity with a list of
>> enums defined as:
>> @ElementCollection
>> private List<VerbForm> verbForms;
>> I can access the verbForms in many cases with no problems, but in one
>> particular case where this entity is nested within other entities, when I
>> try to reference it, I get a cast error.
>> Here is a log from a normal/good case with my debug info showing that it
>> is accessed as the correct enum class:
>> [#|2010-04-23T15:08:21.113-0400|INFO|glassfishv3.0|com.leadingstep.grammardb.sentences|_ThreadID=27;_ThreadName=Thread-1;|calling
>> addAuxVerbs, index: 0|#]
>> [#|2010-04-23T15:08:21.113-0400|INFO|glassfishv3.0|com.leadingstep.grammardb.sentences|_ThreadID=27;_ThreadName=Thread-1;|verbForm:
>> ED|#]
>> [#|2010-04-23T15:08:21.113-0400|INFO|glassfishv3.0|com.leadingstep.grammardb.sentences|_ThreadID=27;_ThreadName=Thread-1;|class:
>> class com.leadingstep.grammardb.verbs.VerbForm|#]
>> [#|2010-04-23T15:08:21.113-0400|INFO|glassfishv3.0|com.leadingstep.grammardb.sentences|_ThreadID=27;_ThreadName=Thread-1;|no
>> cast issues w/addAuxVerbs|#]
>> -----------------
>> And here is the log when the problem occurs:
>> [#|2010-04-23T15:09:23.582-0400|INFO|glassfishv3.0|com.leadingstep.grammardb.sentences|_ThreadID=26;_ThreadName=Thread-1;|calling
>> addAuxVerbs, index: 0|#]
>> [#|2010-04-23T15:09:23.582-0400|INFO|glassfishv3.0|com.leadingstep.grammardb.sentences|_ThreadID=26;_ThreadName=Thread-1;|verbForm:
>> ED|#]
>> [#|2010-04-23T15:09:23.582-0400|WARNING|glassfishv3.0||_ThreadID=26;_ThreadName=Thread-1;|A
>> system exception occurred during an invocation on EJB GrammarDBBean
>> method public java.util.List
>> com.leadingstep.grammardb.beans.GrammarDBBean.fetchAllModifiedNounValues(com.leadingstep.grammardb.nouns.ModifiedNoun)
>> javax.ejb.EJBException
>> at
>> com.sun.ejb.containers.BaseContainer.processSystemException(
>> <snip>
>> Caused by: java.lang.ClassCastException: java.lang.String cannot be cast
>> to com.leadingstep.grammardb.verbs.VerbForm
>> at
>> com.leadingstep.grammardb.sentences.Predicate.fetchValue(
>> -------------------
>> I can include more of the error message if it would be helpful, but I'm
>> really at a loss to understand how JPA can access the field and correctly
>> interpret it as an Enum class in one instance, but then access the same
>> field at the same point in code later and think it is a String that needs
>> to be converted?  This same entity is embedded indirectly in four other
>> different entities and I can access it correctly in three out of four of
>> those cases.  I can't begin to imagine what could be different in the way
>> it's accessed that would cause this problem.
>> I had been using the EclipseLink 1.1.2 - Galileo library, but upgraded to
>> EclipseLink 2.0.1 and that didn't help or change anything.  I'm running
>> on a Mac with GlassFish Tools Bundle for Eclipse, v1.2.
>> Can anyone give me some clues as to what might be going on and how I can
>> resolve this issue?
>> Thanks so much,
>> Renee

View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top