users@glassfish.java.net

JPA enum access cast issue

From: <glassfish_at_javadesktop.org>
Date: Fri, 23 Apr 2010 12:48:44 PDT

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:

[#|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|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_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(BaseContainer.java:5070)

<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(Predicate.java:1047)

-------------------

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?

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.

Can anyone give me some clues as to what might be going on and how I can resolve this issue?

Thanks so much,
Renee
[Message sent by forum member 'drrevis']

http://forums.java.net/jive/thread.jspa?messageID=398724