right, we want to serialize the bizz objects created by application user into xml so its reusable by user. (some bizz requirement). Those bizz objects have a copy in relational database too.
At the runtime, copy all the value of states(with getter/setter or direct member access with "." operator) from the detached instance to another "new" operator constructed instance, the new instance can be serilized to xml with castor. But It can not use clone method to do this copy, the cloned member will be not serialized. The clone method will copy pcStateManager or sm member (value is null) into the new instance, which is the only difference between new instance and detached instance. Since both instances are using the same class in the same JVM, the read/writeObject() method should be same. (Will check it ) More information of castor properties: org.exolab.castor.parser=org.xml.sax.helpers.XMLReaderAdapter org.exolab.castor.xml.serializer.factory=org.exolab.castor.xml.XercesJDK5XMLSerializerFactory org.exolab.castor.parser=com.sun.org.apache.xerces.internal.parsers.SAXParser Persistence.xml: tried <property name="openjpa.DetachState" value="all(DetachedStateField=false)"/> <property name="openjpa.DetachState" value="loaded(DetachedStateField=false)"/> 1. decompile the enhanced classes (with jad or something similar) to see the code that has been generated for serialization methods such as read/writeObject(), if any. 2. What does Castor require/assume to marshal an instance to XML? 3. Verify the state (field values) of the detached instance before Castor tries to marshal it. Thanks for the quick reply. Step 1. enhanced the persistent classes at the build time Step 2. added the openjpa.DetachState property, also tried other DetachState setting. Result: Castor still can not serialize the detached objects. The marshall result is still empty xml. Any suggestion? Hello, try the following configuration [1] <property name="openjpa.DetachState" value="loaded(DetachedStateField=false)"/> OpenJPA detached object instance x (optionally) can carry a StateManager (pcStateManager) instance sm(x) which can track changes in x while x is not under OpenJPA managed context. This makes merging of x into a OpenJPA managed context more effective. The above configuration makes the detached instance x' serialization compatible with original x. Serialization behavior does change based on the detach state configuration and most likely not liked by Castor's marshaller. To narrow the cause, you should also enhance your domain classes at build-time [2]. [1] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_graph [2] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_enhance_build 1. Environment: java1.5, OpenJPA 1.2.1 , castor 1.2 2. any object retrieved from database by OpenJPA cannot be serialized to xml by castor. No error message from org.exolab.castor.xml.Marshaller . The result xml file is completely empty 3. When the same persistent class is instantiated by "new" operator, the instantiated object can be serialized by castor. 4. The only different between "openJPA detached objects" and "new instantiated objects" is the "openJPA detached objects" has member pcStateManager = null. Questions: 1. is this behavior related the pcStateManager member in the detached persistent objects? 2. What is the purpose of pcStateManager ? 3.How does it affect the serialization behavior ? -- View this message in context: http://n2.nabble.com/openJPA-detached-object-can-not-be-serialized-by-Castor.--is-it-related-with-pcStateManager--tp2636117p2640850.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
