4 Replies Latest reply on Jul 13, 2005 6:46 AM by Clemens Greshake

    org.hibernate.type.SerializationException: could not deseria

    Enzo Poeta Newbie

      Hi sorry by the other post ( this same subject and unreadable )
      Can anyone help me with this problem ?

      I got this stack trace when my client had tried to access a entity bean ( passing by a stateful bean ) whith to one-to-many annotations with this syntax :

      
      @OneToMany
      @AssociationTable(
       table=@Table(name="rkos60"),
       joinColumns = { @JoinColumn( name="id_usuar") },
       inverseJoinColumns = { @JoinColumn( name="cd_ccust") }
      )
      public Collection<CentroCusto> getCCustosAutorizados()
      {
       return ccustos;
      }
      
      @OneToMany
      @AssociationTable(
       table=@Table(name="rkos80"),
       joinColumns = { @JoinColumn( name="id_usuar") },
       inverseJoinColumns = { @JoinColumn( name="tip_perf") }
      )
      
      



      This is the Error :


      org.jboss.ejb3.stateful.ForwardId: org.hibernate.type.SerializationException: could not deserialize
      10:05:32,001 INFO [STDOUT] at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:162)
      10:05:32,001 INFO [STDOUT] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
      10:05:32,001 INFO [STDOUT] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:74)
      10:05:32,001 INFO [STDOUT] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:325)
      10:05:32,002 INFO [STDOUT] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:201)
      10:05:32,006 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:259)
      10:05:32,006 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:327)
      10:05:32,006 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:147)
      10:05:32,007 INFO [STDOUT] Caused by: org.hibernate.type.SerializationException: could not deserialize
      10:05:32,007 INFO [STDOUT] at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:211)
      10:05:32,007 INFO [STDOUT] at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:234)
      10:05:32,007 INFO [STDOUT] at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:78)
      10:05:32,007 INFO [STDOUT] at org.hibernate.type.SerializableType.get(SerializableType.java:39)
      10:05:32,008 INFO [STDOUT] at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
      10:05:32,008 INFO [STDOUT] at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
      10:05:32,008 INFO [STDOUT] at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
      10:05:32,008 INFO [STDOUT] at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1695)
      10:05:32,008 INFO [STDOUT] at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:918)
      10:05:32,008 INFO [STDOUT] at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:874)
      10:05:32,008 INFO [STDOUT] at org.hibernate.loader.Loader.getRow(Loader.java:787)
      10:05:32,008 INFO [STDOUT] at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:293)
      10:05:32,008 INFO [STDOUT] at org.hibernate.loader.Loader.doQuery(Loader.java:387)
      10:05:32,008 INFO [STDOUT] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
      10:05:32,009 INFO [STDOUT] at org.hibernate.loader.Loader.doList(Loader.java:1515)
      10:05:32,009 INFO [STDOUT] at org.hibernate.loader.Loader.list(Loader.java:1498)
      10:05:32,009 INFO [STDOUT] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
      10:05:32,009 INFO [STDOUT] at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:266)
      10:05:32,009 INFO [STDOUT] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:791)
      10:05:32,009 INFO [STDOUT] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
      10:05:32,009 INFO [STDOUT] at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:588)
      10:05:32,009 INFO [STDOUT] at org.jboss.ejb3.entity.QueryImpl.getSingleResult(QueryImpl.java:66)
      10:05:32,009 INFO [STDOUT] at ordemservico.beans.stateful.UserManagerBean.searchUser(UserManagerBean.java:25)
      10:05:32,010 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      10:05:32,010 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      10:05:32,010 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      10:05:32,010 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
      10:05:32,010 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:77)
      10:05:32,010 INFO [STDOUT] at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:134)
      10:05:32,010 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:66)
      10:05:32,010 INFO [STDOUT] at org.jboss.aspects.tx.TxSupport.invokeInOurTx(TxSupport.java:141)
      10:05:32,010 INFO [STDOUT] at org.jboss.aspects.tx.TxSupport$Required.serverInvoke(TxSupport.java:438)
      10:05:32,011 INFO [STDOUT] at org.jboss.aspects.tx.TxInterceptor.internalInvoke(TxInterceptor.java:112)
      10:05:32,011 INFO [STDOUT] at org.jboss.aspects.tx.TxInterceptor.invoke(TxInterceptor.java:60)
      10:05:32,011 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:66)
      10:05:32,011 INFO [STDOUT] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:72)
      10:05:32,055 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:66)
      10:05:32,056 INFO [STDOUT] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:80)
      10:05:32,056 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:66)
      10:05:32,056 INFO [STDOUT] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:90)
      10:05:32,056 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:66)
      10:05:32,056 INFO [STDOUT] at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:156)
      10:05:32,056 INFO [STDOUT] ... 7 more
      10:05:32,057 INFO [STDOUT] Caused by: java.io.StreamCorruptedException: invalid stream header
      10:05:32,057 INFO [STDOUT] at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:753)
      10:05:32,057 INFO [STDOUT] at java.io.ObjectInputStream.<init>(ObjectInputStream.java:268)
      10:05:32,057 INFO [STDOUT] at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:246)
      10:05:32,057 INFO [STDOUT] at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:203)
      


      Thanks !

        • 1. Re: org.hibernate.type.SerializationException: could not des
          Leos Urban Newbie

          Do entitity beans implement java.io.Serializable?
          If yes then send here EB from both side of relation...

          Leonell

          • 2. Re: org.hibernate.type.SerializationException: could not des
            Enzo Poeta Newbie

            Hi Leonel ... the beans are implementing java.oi.Serializable..
            The bean codes .....

            /*
             * Created on May 6, 2004
             *
             * To change the template for this generated file go to
             * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
             */
            package ordemservico.beans.entity;
            
            import java.io.Serializable;
            
            import javax.persistence.Column;
            import javax.persistence.Entity;
            import javax.persistence.GeneratorType;
            import javax.persistence.Id;
            import javax.persistence.Table;
            
            
            /**
             * @author Enzo Telles Poeta
             *
             * To change the template for this generated type comment go to
             * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
             */
            
            
            @Entity
            @Table(name = "rkos90")
            public class CentroCusto implements Serializable
            {
             // Atributos
             private String codigoCCusto;
             private String emailResponsavel;
             private String descricaoCCusto;
            
            
            
             // metodos
            
             // retorna o atributo descricaoCCusto
             @Column(updatable = true, name = "dc_ccust", nullable = false, length = 40)
             public String getDescricaoCentroCusto()
             {
             return descricaoCCusto;
             }
            
             // retorna o atributo codigoCCusto
             @Id(generate = GeneratorType.NONE)
             @Column(updatable = true, name = "cd_ccust", nullable = false, length = 5)
             public String getCodigoCentroCusto()
             {
             return codigoCCusto;
             }
            
             // retorna o atributo emailResponsavel
             @Column(updatable = true, name = "end_email_resp", nullable = true, length = 40)
             public String getEmailResponsavel()
             {
             return emailResponsavel;
             }
            
             // seta o atributo emailResponsavel
             public void setEmailResponsavel(String email)
             {
             this.emailResponsavel=email;
             }
            
             // insere o atributo codigoCCusto ( usado na criacao do TO pelo DAO)
             public void setCodigoCentroCusto(String codCCusto)
             {
             this.codigoCCusto=codCCusto;
             }
            
             // seta o atributo descricaoCCusto
             public void setDescricaoCentroCusto(String descCCusto)
             {
             this.descricaoCCusto = descCCusto;
             }
            
            }
            

            /*
             * Created on 05/05/2004
             *
            */
            package ordemservico.beans.entity;
            
            import java.io.Serializable;
            
            import javax.persistence.Column;
            import javax.persistence.Entity;
            import javax.persistence.GeneratorType;
            import javax.persistence.Id;
            import javax.persistence.Table;
            
            @Entity
            @Table(name = "rkos70")
            public class Perfil implements Serializable
            {
             // Atributos
            
             private String tipoPerfil;
             private String descricao;
            
            
             // metodos
            
             @Id(generate = GeneratorType.NONE)
             @Column(updatable = true, name = "tip_perf", nullable = false, length = 1)
             public String getId()
             {
             return tipoPerfil;
             }
            
             @Column(updatable = true, name = "dc_perf", nullable = false, length = 20)
             public String getDescricao()
             {
             return descricao;
             }
            
             public void setId(String tipoP)
             {
             this.tipoPerfil = tipoP;
             }
            
             public void setDescricao(String desc)
             {
             this.descricao = desc;
             }
            
            }
            

            /*
             * Created on Apr 26, 2004
             *
             * To change the template for this generated file go to
             * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
             */
            package ordemservico.beans.entity;
            
            /**
             * @author Enzo Telles Poeta
             *
             * To change the template for this generated type comment go to
             * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
             */
            import java.io.Serializable;
            import java.util.ArrayList;
            import java.util.Collection;
            
            
            
            import javax.persistence.CascadeType;
            import javax.persistence.Column;
            import javax.persistence.Entity;
            import javax.persistence.FetchType;
            import javax.persistence.GeneratorType;
            import javax.persistence.Id;
            import javax.persistence.JoinColumn;
            import javax.persistence.JoinTable;
            import javax.persistence.OneToMany;
            import javax.persistence.Table;
            
            @Entity
            @Table(name = "rkos01")
            public class Usuario implements Serializable
            {
             // Atributos
             private String nome;
             private String email;
             private int matricula;
             private CentroCusto ccusto;
             private String login;
             private Collection<Perfil> perfis;
             private boolean ativo;
             private int tipoUsuario;
             private Collection<CentroCusto> ccustos;
             private String passwordUsuario;
            
            
             //metodos
            
             // Collectiona os centros de custo para os quais o usuario pode solicitar Oss
            
             @OneToMany
             @JoinTable(
             table=@Table(name="rkos60"),
             joinColumns = { @JoinColumn( name="id_usuar") },
             inverseJoinColumns = { @JoinColumn( name="cd_ccust") }
             )
             public Collection<CentroCusto> getCCustosAutorizados()
             {
             return ccustos;
             }
            
             // teste
             public void setCCustosAutorizados(Collection<CentroCusto> ccustos)
             {
             this.ccustos=ccustos;
             }
            
             // Collectiona os perfis que possui o usuario
            
             @OneToMany
             @JoinTable(
             table=@Table(name="rkos80"),
             joinColumns = { @JoinColumn( name="id_usuar") },
             inverseJoinColumns = { @JoinColumn( name="tip_perf") }
             )
             public Collection<Perfil> getPerfis()
             {
             return perfis;
             }
            
             //teste2
             public void setPerfis(Collection<Perfil> perfis)
             {
             this.perfis=perfis;
             }
            
             // retorna o atributo password
             @Column(updatable = true, name = "pwd_usuar", nullable = false, length = 8)
             public String getPassword()
             {
             return passwordUsuario;
             }
            
             // retorna o atributo nome
             @Column(updatable = true, name = "nome_funcio", nullable = false, length = 40)
             public String getNome()
             {
             return nome;
             }
            
             // retorna o atributo Centro de Custo
             @Column(updatable = true, name = "cd_ccust", nullable = false, length = 5)
             public CentroCusto getCentroCusto()
             {
             return ccusto;
             }
            
             // retorna o atributo email
             @Column(updatable = true, name = "end_email", nullable = true, length = 40)
             public String getEmail()
             {
             return email;
             }
            
             // retorna o atributo matricula
             @Column(updatable = true, name = "num_matr_unicamp", nullable = true)
             public int getMatricula()
             {
             return matricula;
             }
            
             // retorna o atributo tipoUsuario
             @Column(updatable = true, name = "tp_funcio", nullable = true)
             public int getTipo()
             {
             return tipoUsuario;
             }
            
             // retorna o atributo Login
             @Id(generate = GeneratorType.NONE)
             @Column(updatable = true, name = "id_usuar", nullable = false, length = 7)
             public String getLogin()
             {
             return login;
             }
            
             // Retorna o atributo ativo
             @Column(updatable = true, name = "fl_ativ_funcio", nullable = false, length = 7)
             public boolean getStatus()
             {
             return ativo;
             }
            
             // seta o atributo nome
             public void setNome(String nomeUsuario)
             {
             this.nome=nomeUsuario;
             }
            
             // seta o atributo password
             public void setPassword(String password)
             {
             this.passwordUsuario = password;
             }
            
             // seta o atributo area
             public void setCentroCusto(CentroCusto ccusto)
             {
             this.ccusto=ccusto;
             }
            
             // seta o atributo email
             public void setEmail(String mail)
             {
             this.email=mail;
             }
            
             // seta o atributo matricula
             public void setMatricula(int codMatricula)
             {
             this.matricula=codMatricula;
             }
            
             // seta o atributo tipoUsuario
             public void setTipo(int codTipo)
             {
             this.tipoUsuario=codTipo;
             }
            
             // seta o atributo Login
             public void setLogin(String loginUsuario)
             {
             this.login=loginUsuario;
             }
            
             // Seta o atributo ativo
             public void setStatus(boolean estado)
             {
             this.ativo=estado;
             }
            
            
             // adiciona um novo centro de custo a Collectionagem
             public void adicionarCentroCustoAutorizado(CentroCusto ccusto)
             {
             if (ccustos == null)
             {
             ccustos = new ArrayList<CentroCusto>();
             }
            
             if (ccustos.contains(ccusto)==false)
             {
             ccustos.add(ccusto);
             }
             }
            
             // remove um centro de custo da Collectionagem
             public void removerCentroCustoAutorizado(CentroCusto ccusto)
             {
             if (ccustos == null)
             {
             ccustos = new ArrayList<CentroCusto>();
             }
            
             if (ccustos.contains(ccusto)==true)
             {
             ccustos.remove(ccusto);
             }
             }
            
             // adiciona um novo perfil ao usuario
             public void adicionarPerfil(Perfil perfil)
             {
             if (perfis == null)
             {
             perfis = new ArrayList<Perfil>();
             }
             if (perfis.contains(perfil)==false)
             {
             perfis.add(perfil);
             }
             }
            
             // Remove um perfil de usuario
             public void removerPerfil (Perfil perfil)
             {
             if (perfis == null)
             {
             perfis = new ArrayList<Perfil>();
             }
             if (perfis.contains(perfil)==true)
             {
             perfis.remove(perfil);
             }
             }
            
            }
            


            It seems that the problem occurs when my clients calls the method searchUser() in the following stateful bean :

            package ordemservico.beans.stateful;
            
            
            
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.persistence.EntityManager;
            import javax.persistence.PersistenceContext;
            
            import ordemservico.beans.entity.Usuario;
            
            @Stateful
            public class UserManagerBean implements UserManagerRemote
            {
            
             private @PersistenceContext(unitName="manager_sisos2") EntityManager manager;
            
            
             @Remove
             public void remover()
             {
             //NAO FAZ NADA
             }
            
             public Usuario searchUser(String userName)
             {
             return (Usuario)manager.createQuery("from Usuario usu where usu.login = :id").setParameter("id", userName).getSingleResult();
             }
            }
            


            this stateful implements the following interface :

            
            package ordemservico.beans.stateful;
            
            import javax.ejb.Remote;
            import javax.ejb.Remove;
            
            import ordemservico.beans.entity.Usuario;
            
            @Remote
            public interface UserManagerRemote
            {
             public Usuario searchUser(String userName);
             @Remove public void remover();
            }
            
            


            Thanks for your help !

            • 3. Re: org.hibernate.type.SerializationException: could not des
              Leos Urban Newbie

              I tested your code and it works :-)
              I am using JBOSS 4.0.1SP + EJB3 Beta1.

              Here is simple client:

               um = (UserManagerRemote) ctx.lookup(UserManagerRemote.class.getName());
              
               CentroCusto cc1 = new CentroCusto();
               cc1.setCodigoCentroCusto("00001"); //ID
               cc1.setDescricaoCentroCusto("DescricaoCentroCusto");
               cc1.setEmailResponsavel("aaa@aaa.aaa");
               um.insertCentroCusto(cc1); //persist
               cc1 = um.findCentroCusto("00001"); //load
               System.out.println("CC1");
              
               CentroCusto cc2 = new CentroCusto();
               cc2.setCodigoCentroCusto("00002"); //ID
               cc2.setDescricaoCentroCusto("DescricaoCentroCusto");
               cc2.setEmailResponsavel("aaa@aaa.aaa");
               um.insertCentroCusto(cc2); //persist
               cc2 = um.findCentroCusto("00001"); // load
               System.out.println("CC2");
              
               Perfil p = new Perfil();
               p.setId("1");
               p.setDescricao("Descricao 000001");
               um.insertPerfil(p); // persist
               p = um.findPerfil("1"); // load
               System.out.println("Perfil");
              
               Usuario o = new Usuario();
               o.setLogin("login"); //ID
               o.setCentroCusto(cc1);
              
               ArrayList<CentroCusto> items1 = new ArrayList<CentroCusto>();
               {
               items1.add(cc2);
               }
               o.setCCustosAutorizados(items1);
              
               ArrayList<Perfil> items2 = new ArrayList<Perfil>();
               {
               items2.add(p);
               }
               o.setPerfis(items2);
               o.setEmail("asas@asas.aa");
               o.setMatricula(1);
               o.setNome("Leonell");
               o.setPassword("****");
               o.setStatus(true);
               o.setTipo(1);
               // ------------------------------------
               um.insertUsuario(o);
               // ------------------------------------
               Usuario x = um.searchUser("login");
               System.out.println("Nome:"+x.getNome());
              


              As you can see I added some method to your session bean for persist and load entities Perfil and CentroCusto.

              Hope it helps.

              Leonell

              • 4. Re: org.hibernate.type.SerializationException: could not des
                Clemens Greshake Newbie

                Hi enztp,

                i have the same problem. What is the solution for the problem?

                Thanks!