openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jere McDevitt" <>
Subject Serialization between ehanced and non-enhanced objects
Date Thu, 28 Jun 2007 02:25:47 GMT
The documentation makes the following claim:


2.4.  Serializing Enhanced Types 

By default, OpenJPA maintains serialization compatibility between the
enhanced and unenhanced versions of a class. This allows you to serialize
instances between a server using OpenJPA and a client that does not have
access to enhanced classes or OpenJPA libraries. In some cases, however, you
can make the persist and attach processes more robust and efficient by
allowing breaks in serialization compatibility. See Section
ref_guide_detach_graph>  1.3, " Defining the Detached Object Graph " for


However, in actual practice I have not been able to make this work.  When I
have a class structure like:



public class User {



            private String userId;



            private String password;






            List<Role>  roles;





public class Role {



            private String roleName;




and I enhance these classes, the enhancer adds into the User.class file an
additional object of type$util$ArrayList$proxy

which actually wrapps the 'roles' field.  Additionally, all of the actual
field attributes are encapsulated inside another object called 'default'.  I
can't seem to serialize in any manner that will work,  either with
ObjectOutputStream, java.beans.XMLEncoder or XStream.toXML,


When an attempt is made to deserialize in another JVM that does not have the
enhanced classes, and does not have the openjpa package at all, it fails.
Straight ObjectOutputStream fails with class not found for the above
ArrayList$proxy, XMLCoder generates NullPointerExceptions because it can't
find the class, and XMLStream doesn't recognized either the class or the
'default' tag that was generated on the server side.


I tried adding in the 


@DetachedState private Object state 


but that doesn't seem to do anything but add an additional field that gets
filled with a byte array.



The XML that is provided by java.beans.XMLEncode which shows the location of
the proxy object is:


<?xml version="1.0" encoding="UTF-8"?> 
<java version="1.6.0" class="java.beans.XMLDecoder"> 
 <object class="commons.UserProfile"> 
  <void property="emailAddress"> 
  <void property="firstName"> 
  <void property="lastName"> 
  <void property="password"> 
  <void property="phoneNumber"> 
  <void property="roles"> 
   <object class="$util$ArrayList$proxy"> 
    <void method="add"> 
     <object id="Role0" class="commons.Role"> 
      <void property="roleName"> 
    <void method="add"> 
     <object id="Role1" class="commons.Role"> 
      <void property="roleName"> 
    <void method="add"> 
     <object idref="Role0"/> 
    <void method="add"> 
     <object idref="Role1"/> 
  <void property="userId"> 

So how do you actually implement serialization from an enhanced server side
object to a non-enhanced client side object?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message