openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tedman Leung <>
Subject Eager fetching of PersistentCollection gives error
Date Thu, 02 Apr 2009 00:49:10 GMT
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 :

	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(
		at org.apache.openjpa.kernel.BrokerImpl.find(
		at org.apache.openjpa.kernel.DelegatingBroker.find(
		at org.apache.openjpa.persistence.EntityManagerImpl.find(
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(
		at java.lang.reflect.Method.invoke(
	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(
		at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(
		at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(
		at org.apache.openjpa.kernel.DelegatingStoreManager.initialize(
		at org.apache.openjpa.kernel.ROPStoreManager.initialize(
		at org.apache.openjpa.kernel.BrokerImpl.initialize(
		at org.apache.openjpa.kernel.BrokerImpl.find(

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

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

View raw message