So I have a more clear picture of this error now. Quite simply eager 
fetching of a persistent collection of strings fails.

as an example :

        @PersistentCollection(fetch=FetchType.EAGER)
        private HashSet<String> testStrings=new HashSet<String>();

Just create the entity, add a string to the collection, the merge / 
persist it.

Then clear the entityManager and any second level caches you have (or just 
stop the jvm), and load the entity back and I get 

        <openjpa-1.2.1-r752877:753278 nonfatal general error> 
        org.apache.openjpa.persistence.PersistenceException: java.lang.String 
cannot be cast to org.apache.openjpa.enhance.PersistenceCapable
                at 
org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:875)
                at 
org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:769)
                at 
org.apache.openjpa.kernel.DelegatingBroker.find(DelegatingBroker.java:183)
                at 
org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:452)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:597)
        ...
        Caused by: java.lang.ClassCastException: java.lang.String cannot be 
cast to org.apache.openjpa.enhance.PersistenceCapable
                at 
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setInverseRelation(JDBCStoreManager.java:408)
                at 
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:380)
                at 
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:278)
                at 
org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:111)
                at 
org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:57)
                at 
org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:894)
                at 
org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:852)

 
Note that you must not be reloading the entity from memory, i.e.
you must clear the entity manager and make sure the entity cache is
off, or restart the jvm. 

If you don't turn the entity caches off, it will just give you
back what you peristed and it will look like it works.

Anyone got any ideas on how to fix or work around this? 
I'd really prefer my entity detached but I want this data
fetched eagerly.
-- 
                                                           Ted Leung
                                                           [email protected]

// /*
You know things are getting a little fishy when you're commenting out 
comments.
// */

Reply via email to