One-To-Many RElations Serialization

37 views
Skip to first unread message

Bruno Sandivilli

unread,
Oct 6, 2011, 6:58:41 PM10/6/11
to google-we...@googlegroups.com
I'm getting this error when my RPC returns a list of a custom object:
Type 'org.datanucleus.sco.backed.List' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

Juan Pablo Gardella

unread,
Oct 7, 2011, 11:10:41 AM10/7/11
to google-we...@googlegroups.com
What's your question?

2011/10/6 Bruno Sandivilli <bruno.sa...@gmail.com>
I'm getting this error when my RPC returns a list of a custom object:
Type 'org.datanucleus.sco.backed.List' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Bruno Sandivilli

unread,
Oct 7, 2011, 1:12:38 PM10/7/11
to google-we...@googlegroups.com
How can i serializa this List<MyClass> ?

2011/10/7 Juan Pablo Gardella <gardella...@gmail.com>

Juan Pablo Gardella

unread,
Oct 7, 2011, 2:29:20 PM10/7/11
to google-we...@googlegroups.com
You can see the same problem but with hibernate here. In this page show some strategies to resolve the problem. In my case I don't adopt this strategies. I do a filter. In Pro Web 2.0 explain the use of a filter. A class that, in your case, for example convert org.datanucleus.sco.backed.List in java.util.List. This filter intercept the classes before send to client. Here you have an example of a Hibernate filter compatible with GWT 2.4.0 and how integrate in a sample project.

Juan


2011/10/7 Bruno Sandivilli <bruno.sa...@gmail.com>

Bruno Sandivilli

unread,
Oct 7, 2011, 4:10:37 PM10/7/11
to google-we...@googlegroups.com
Thanks Buddy!
But if i'm not using Hibernate? I'm using pure GWT, do i have to use the <filter> in web.xml? How can i achieve this? Thanks

Bruno Sandivilli

unread,
Oct 7, 2011, 7:43:23 PM10/7/11
to google-we...@googlegroups.com
PersistenceManager pm = PMF.get().getPersistenceManager();
javax.jdo.Query query = (javax.jdo.Query) pm.newQuery(Objetos.class);
query.setFilter("name == nameParam");
query.declareParameters("String nameParam");
List<MyInnerList> listaMyInnerList = new ArrayList<MyInnerList>();
List<MyMain> listaMyMainList  = (List<MyMain>) query.execute(nameParam);
if(listaMyMainList .size() > 0)
{
listaMyInnerList.addAll(listaMyMainList.get(0).getMyInnerList());
}
return new ArrayList(listaMyInnerList);
                        or
                       return listaMyInnerList;
it gives the same error of Type 'org.datanucleus.sco.backed.ArrayList' 

anyone?

2011/10/7 Bruno Sandivilli <bruno.sa...@gmail.com>

Jens

unread,
Oct 8, 2011, 8:30:38 AM10/8/11
to google-we...@googlegroups.com
JDO does some byte code enhancement to your entities and JDO will replace java.util.List/ArrayList in entity classes with an implementation provided by JDO, e.g. org.datanucleus.sco.backed.ArrayList. You have the same problem when using Hibernate or any other JPA implementation because they all enhance class byte code to be able to support some JDO/JPA features. Thats why Juan mentioned Hibernate.

You either have to find a way to convert these specific JDO implementations back to their java counter parts before sending them back to the browser or you have to use a Data Transfer Object (DTO pattern) to return your data.

Looking at your code it seems like you somewhere missed to convert a JDO List into a java.util.List in MyInnerList.class. Otherwise you shouldn't see the exception anymore as you already copy things to a normal java.util.ArrayList.

Patrick Tucker

unread,
Oct 9, 2011, 10:56:05 AM10/9/11
to Google Web Toolkit
Does MyClass implement IsSerializable or Serializable?

On Oct 6, 6:58 pm, Bruno Sandivilli <bruno.sandivi...@gmail.com>
wrote:

Brandon Donnelson

unread,
Oct 9, 2011, 6:17:57 PM10/9/11
to google-we...@googlegroups.com
Detach the object from JDO. 

Brandon Donnelson

unread,
Oct 9, 2011, 6:19:36 PM10/9/11
to google-we...@googlegroups.com

@PersistenceCapable(detachable="true")

detached = pm.detachCopy(employee);

Those will create a java.util List object. That should fix it.

Brandon 

Bruno Sandivilli

unread,
Oct 10, 2011, 4:30:12 PM10/10/11
to google-we...@googlegroups.com
Thanks for the help from you guys!
But, yes im using IsSEriazeble. I've changed my code to detachable in both classes, but, when i call:

if(listMyClass.size() > 0)
{
for (MyClass myClass : listMyClass) {
return (pm.detachCopy(myClass.getMyInnerClassList()));
}
}
return null;


gives me : The class "org.datanucleus.sco.backed.List" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.


debugging this, i've reached this : assertClassPersistable in the class ObjectMAnagerImpl. This function : 

    public void assertClassPersistable(Class cls)
    {
        if (cls != null && !getOMFContext().getApiAdapter().isPersistable(cls) && !cls.isInterface())
        {
            throw new ClassNotPersistableException(cls.getName());
        }
        if (!hasPersistenceInformationForClass(cls))
        {
            throw new NoPersistenceInformationException(cls.getName());
        }
    }


2011/10/9 Brandon Donnelson <branfl...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Brandon Donnelson

unread,
Oct 10, 2011, 5:19:40 PM10/10/11
to google-we...@googlegroups.com
What type of owned List do you have?

Have a good day,
Brandon Donnelson

Bruno Sandivilli

unread,
Oct 10, 2011, 5:52:37 PM10/10/11
to google-we...@googlegroups.com
I have a simple Class with getters and setters, and : 

@PersistenceCapable(identityType=  IdentityType.APPLICATION, detachable = "true" )
class MyInnerClass  implements IsSerializable {

@Persistent(defaultFetchGroup = "true")
private MyClass myClass;


@PrimaryKey
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
String Id; 
}

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true" )
public class MyClass implements IsSerializable {
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
@PrimaryKey
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
String Id;
@Persistent(mappedBy = "myClass")
List<MyInnerClass> listMyInnerClass;
}


2011/10/10 Brandon Donnelson <branfl...@gmail.com>

Brandon Donnelson

unread,
Oct 10, 2011, 6:39:59 PM10/10/11
to google-we...@googlegroups.com
Hmmm, I don't see anything specific sticking out. What I do know so far is that your error is because you can't serialize org.datanucleus.sco.backed.List which happens when the collection doesn't get detached from the datastore. You can pause/break on the the variable before return rpc transport and see if it was detached by looking at the var type. On a successful detachment it will be a java.util.List collection and not org.datanucleus.sco.backed.List. Sorry I might be speaking to the choir. :) 

Here is how I setup my owned collections: 
  @Persistent(defaultFetchGroup = "true", dependentElement = "true")
 
private LinkedHashSet<CourseJdo> courses;

The iteration or query you have above doesn't look right to me. I'm not sure if your detaching the child or parent.

Here is one of my queries in which I use detach.
  private LearningPlanData[] queryData(LearningPlanDataFilter filter) {

   
String qfilter = null;

   
// filter a batch of ids
   
List<Key> keysList = null;
   
if (filter.getUseIds() == true) {
      keysList
= getFilterForIds(filter);
     
if (keysList != null) {
        qfilter
= ":keys.contains(key)";
     
}
     
if (keysList == null || keysList.size() == 0) {
       
return null;
     
}
   
}

   
ArrayList<LearningPlanData> a = new ArrayList<LearningPlanData>();
   
PersistenceManager pm = sp.getPersistenceManager();
   
try {
     
Query q = pm.newQuery("select from " + LearningPlanJdo.class.getName());
     
if (qfilter != null) {
        q
.setFilter(qfilter);
     
}
      q
.setRange(filter.getRangeStart(), filter.getRangeFinish());

     
List<LearningPlanJdo> ids = null;
     
if (filter.getUseIds() == true && keysList != null) {
        ids
= (List<LearningPlanJdo>) q.execute(keysList);

     
} else {
        ids
= (List<LearningPlanJdo>) q.execute();
     
}

     
Iterator<LearningPlanJdo> itr = ids.iterator();
     
while (itr.hasNext()) {
       
LearningPlanJdo j = itr.next();
       
if (j != null) {
          j
.getData();
         
LearningPlanJdo detatched = pm.detachCopy(j);
          a
.add(detatched.getData());
       
}
     
}
      q
.closeAll();
   
} catch (Exception e) {
      e
.printStackTrace();
      log
.log(Level.SEVERE, "", e);
   
} finally {
      pm
.close();
   
}
   
if (a.size() == 0) {
     
return null;
   
}
   
LearningPlanData[] r = new LearningPlanData[a.size()];
    a
.toArray(r);

   
return r;
 
}

Hope that helps,
Brandon Donnelson


Reply all
Reply to author
Forward
0 new messages