1 Reply Latest reply on Mar 5, 2009 9:31 AM by Marius Oancea

    Entity Bean serialization fails in cluster

    Marius Oancea Novice
      I have a Pojo that is stored into SESSION context when user login (UserDetails).

      This Pojo has:

      public class UserDetails implements Serializable {

           private User user;
           private Set<Usergroup> groups;
      ...
      }


      User and Usergroup are Entity beans and are serializable.

      The error i get is:
      java.io.NotSerializableException: java.lang.reflect.Method


      By using SerializationCheckServletFilter I found out the following:
      21:54:13,254 ERROR [SerializationCheckServletFilter] There are problems to
      serialize the value bound to the session key : 'currentUser' problem reports
      follow:
        Cannot serialize : path : 'currentUser : user : groups : [0] : users : [0] :
      groups : [0] : users : [0] : groups : [0] : users : [0] : groups : [0] : users
      : [0] : groups : [0] : users : [0] : groups : [0] : users : [0] : groups : [0]
      : attributes : [0] : attributetemplate : handler' type : 'interface
      javassist.util.proxy.MethodHandler' definedIn : 'class
      my.model.Attributetemplate_$$_javassist_133' value :
      'org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer@8f2669'

      Any Ideea what I can do?
        • 1. Re: Entity Bean serialization fails in cluster
          Marius Oancea Novice
          Problem was solved.

          currentUser : user : groups[0] : users[0] : ... : attributes [0] : attributetemplate was lazy initialised and since the currentUser(of type UserDetails) was put on session, jboss was trying to serialise without having a hibernate session anymore.


          Solution was:

          Modify the class to make user and groups transient and serialize only their keys.
          ============================================================
          public class UserDetails implements Serializable {
          private Integer userId;
          private Set<Integer> groupIds;

          private User user;
          private Set<Usergroup> groups;
          ...

          public void getUser() {
            if (user == null) { // that means this is user details first accessed after deserialization.
              userService = Component.getInstance("userService");
              user = userService.findUser(userId)
            }

            return userId;
          }
          }

          ================================================================

          method getUser was modified to search for the user based on userId when it is not already initialised.