10 Replies Latest reply on Jun 8, 2009 9:44 AM by Wolfgang Knauf

    EJB3: org.hibernate.type.SerializationException: could not d

    Denny Lanners Newbie

      Hi everybody,
      I would get an Output of an Table Road (Oracle Database) via EntityManager and Web Services. I got the following error :
      org.hibernate.type.SerializationException: could not deserialize

      Eclipe3.4.1/Glassfish V2.1/SoapUI 2.5 (for testing)

      Enviroment:

      Class : Location
      IATA (PK)
      Class : Road
      Origin (PK)(FK of IATA)
      Destination (PK)(FK of IATA)

      To manage the composite ID I generated a class RoadPK which is below:

      import java.io.Serializable;
      import javax.persistence.Embeddable;
      @Embeddable
      public class RoadPK implements Serializable {
      
       /**
       * Variable of type Location
       */
       private Location origin = null;
      
       private Location destination = null;
      ......(Getter/Setter).....
      


      Class Road have the attributs(the composite ID).
      I locate the Problem here in the @nameQuery. I can show all availability methods when I write SELECT r.availabilityMethod FROM ROADS r.
      But I can't access origin and destination by SELECT r.origin.iata FROM ROADS r . So my Question is:
      Is my mapping wrong or is there no posssibility to work with Type classes for attributes in composite IDs in EJB3?

      @Entity
      @NamedQuery(
       name = "ROADS.listAll",
       query = "SELECT r FROM ROADS r")/*
      
      @Table(name="ROADS")
      public class ROADS implements Serializable {
      
       private RoadPK roadPK = null;
       private String availabilityMethod = null;
      
       @EmbeddedId
       public RoadPK getRoadPK() {
       return roadPK ;
       }
      
       public void setRoadPK(RoadPK roadPK ) {
       this.roadPK = roadPK ;
       }
       @Column(name="AVAILABILITY_METHOD")
       public String getAvailabilityMethod() {
       return availabilityMethod;
       }
      
      
       public void setAvailabilityMethod(final String availabilityMethodParam) {
       this.availabilityMethod = availabilityMethodParam;
       }
      
      
      }


      Class Location:

      @Entity
      @Table(name = "LOCATIONS")
      public class Location implements Serializable {
      
       private String iata = null;
      
       /**
       * The Roads
       */
       private Set<Road> roadsorigin;
      
       private Set<Road> roadsdestination;
      
       @Id
       @Column(name = "IATA")
       public String getIata() {
       return iata;
       }
      //...................
       @OneToMany(mappedBy = "roadPK.origin", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
       public Set<Road> getRoadsorigin() {
       return roadsorigin;
       }
      
       public void setRoadsorigin(Set<ROAD> roadsorigin) {
       this.roadsorigin= roadsorigin;
       }
      
       @OneToMany(mappedBy = "roadPK.destination", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
       public Set<Road> getRoadsdestination() {
       return roadsdestination;
       }
      
       public void setRoadsdestination(Set<Road> roadsdestination) {
       this.roadsdestination = roadsdestination;
       }
      }


      The class RoadDAO offers the WebServices:

      @WebService
      @Stateless(name="RoadDAO")
      public class RoadDAOimplements Serializable {
      
       @PersistenceContext(name="ResourceDS")
       private EntityManager em;
       // ....
       @SuppressWarnings("unchecked")
       @WebMethod
       @WebResult(name="RoadsList")
       public final List < Road> listRoad() {
       return em.createNamedQuery("Road.listAll").getResultList();
       }
       // ....
      }


      Thanks for reading


        • 1. The Stacktrace
          Denny Lanners Newbie

           

          INFO: EJB5018: An exception was thrown during an ejb invocation on [RoadDAO]
          INFO: javax.ejb.EJBException
           at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3894)
           at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3794)
           at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3596)
           at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:201)
           at $Proxy220.listRoad(Unknown Source)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at com.sun.enterprise.webservice.InvokerImpl.invoke(InvokerImpl.java:78)
           at com.sun.enterprise.webservice.EjbInvokerImpl.invoke(EjbInvokerImpl.java:82)
           at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
           at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
           at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
           at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
           at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
           at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
           at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
           at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
           at com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:147)
           at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
           at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
           at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
           at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
           at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
           at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
           at com.sun.xml.ws.tx.service.TxServerPipe.process(TxServerPipe.java:317)
           at com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:222)
           at com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:133)
           at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
           at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
           at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
           at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
           at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
           at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
           at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
           at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
           at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
           at com.sun.enterprise.webservice.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:113)
           at com.sun.enterprise.webservice.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:87)
           at com.sun.enterprise.webservice.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:228)
           at com.sun.enterprise.webservice.EjbWebServiceServlet.service(EjbWebServiceServlet.java:157)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
           at com.sun.enterprise.web.AdHocContextValve.invoke(AdHocContextValve.java:114)
           at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
           at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
           at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:87)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
           at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
           at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
           at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
           at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
           at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
           at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
           at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
           at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
           at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
           at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
           at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
           at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
           at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
           at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
           at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
          Caused by: javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize
           at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
           at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)
           at lu.luxair.biz.airlines.fromto.dao.RoadDAO.listRoad(RoadDAO.java:50)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
           at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
           at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
           at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
           at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:190)
           ... 63 more
          Caused by: org.hibernate.type.SerializationException: could not deserialize
           at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:188)
           at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:211)
           at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:105)
           at org.hibernate.type.SerializableType.get(SerializableType.java:62)
           at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
           at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
           at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
           at org.hibernate.type.ComponentType.hydrate(ComponentType.java:583)
           at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:298)
           at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1121)
           at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:588)
           at org.hibernate.loader.Loader.doQuery(Loader.java:724)
           at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
           at org.hibernate.loader.Loader.doList(Loader.java:2228)
           at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
           at org.hibernate.loader.Loader.list(Loader.java:2120)
           at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
           at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
           at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
           at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
           at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
           at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
           ... 73 more
          Caused by: java.io.StreamCorruptedException: invalid stream header
           at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:753)
           at java.io.ObjectInputStream.<init>(ObjectInputStream.java:268)
           at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:223)
           at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:180)
           ... 94 more


          • 2. Re: EJB3: org.hibernate.type.SerializationException: could n
            Wolfgang Knauf Master

            Hi,

            I hope I understand your design correct: your "Road" has a PK, which is actually another entity "Location". The "Location" has relationships to other "Road" entities.

            I think this is quite a problematic design, because by loading the Road, it has to fetch the Location, and by fetching the location, it has to fetch all its related Roads (because of FetchType = EAGER), and from there it will fetch the other Locations and so on....

            You suggest two different options:
            1) You could create an artificial Primary Key on "Location" and "RoadPK" just references this ID. The ROADS entity might have a one-to-one-relationship to a Location and an autogenerated ID (instead of the PK of type "Location").
            2) You might also try to set the relataionships from Location to Road to "LAZY". But I don't know whether this works.

            The latter will bring other difficulties: http://www.jboss.org/community/wiki/EJB3relationships

            Hope this helps

            Wolfgang

            • 3. Re: EJB3: org.hibernate.type.SerializationException: could n
              Denny Lanners Newbie

              First, thanks for the fast answer.

              I also tried two to make the FechType to lazy but that didn't change anything.

              But for the first point with the ID.....
              Can you explain me more in detail what do you mean. For example, where to set the ID? Do you want to set an new phyiscal ID in the Tables and to work with it or do you want to change the ID type in ROAD?

              thx

              • 4. Re: EJB3: org.hibernate.type.SerializationException: could n
                Wolfgang Knauf Master

                Hi,

                Exactly, I would use a generated ID column for all of my entities.

                This makes it much easier to maintain the entities, because they all work the same way (call it a "design pattern" ;-) ). And if you use a web client, you have to use the IDs e.g. for lists or as hidden fields for forms, so you need a simple PK.

                Best regards

                Wolfgang

                • 5. Re: EJB3: org.hibernate.type.SerializationException: could n
                  Denny Lanners Newbie

                  Hi,

                  the problem is that i don't have the permission to make changes on the DB because it's a LIVE/Production DB. So problems with releases/changes and so on.
                  I tried to access now my attributs via @NamedQuery like this:
                  SELECT r.roadPK.origin.iata,r.roadPK.destination.iata, r.availabilityMethod FROM Road r

                  but there I got a compiler error:

                  Caused by: org.hibernate.HibernateException: Errors in named queries: Road.listAll
                   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:397)
                   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
                   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
                   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
                   ... 75 more


                  By testing with

                  SELECT r.roadPK.origin, r.roadPK.destination,r.availabilityMethod FROM Route r
                  i didn't get any error but also any output. lol Like i told it before, with SELECT r.availabilityMethod FROM Route r is no problem!

                  So logically I can access my attributs via r.roadPK.origin.iata but I get there the error! So I think that my mapping is wrong.

                  • 6. Re: EJB3: org.hibernate.type.SerializationException: could n
                    Wolfgang Knauf Master

                    Hi,

                    could you post the table structure? Maybe I can help you then...

                    Does the Hibernate exception provide you with any details about the error (in the inner exception)? By the way: your query uses an entity "Route", but in the initial post it was named "ROADs". Has this changed?

                    Best regards

                    Wolfgang

                    Wolfgang

                    • 7. Re: EJB3: org.hibernate.type.SerializationException: could n
                      Denny Lanners Newbie

                      First, Sorry for the Route/Road mismatch! In fact is it Road, i checked it before.

                      The structure:

                      Location ___|_______Road
                      ___________ |____________________

                      IATA PK -----------> ORIGIN PK +FK
                      spacee -----------> DESTINATION PK + FK

                      So IATA is a String of an Location/Place and Road has a StartPoint (ORIGIN) and an EndPoint (DESTINATION). So Road has a double relation with Location.
                      The idea behind this structure, in Java, is to know from one Road, for example, which the Details of the Origin/Destination from type Location are without using SQL and just work with Java classes.

                      Best regards
                      D6L

                      • 8. Re: EJB3: org.hibernate.type.SerializationException: could n
                        Wolfgang Knauf Master

                        Hi,

                        I'm quite stuck now...

                        Doing a bit of google, I found this: http://stackoverflow.com/questions/675519?sort=oldest

                        According to this, you should remove the entity fields from your PK class and just add the primary key fields of the two entities to it. The relationships "original" and destination" are defined on the "Road" entity.

                        Hope this helps. If not: I cannot help further unfortunately...

                        Wolfgang

                        • 9. Re: EJB3: org.hibernate.type.SerializationException: could n
                          Denny Lanners Newbie

                          Hi,

                          I have the same opinion like you know. I must change the PK in DB to get it run.
                          I have already changed it and works fine!

                          Thanks a lot for your time, Wolfgang

                          Best Regards
                          D6L

                          • 10. Re: EJB3: org.hibernate.type.SerializationException: could n
                            Wolfgang Knauf Master

                            Hi,

                            I found the time to create a wiki entry on how do define a relationship with a Join Table:
                            http://www.jboss.org/community/wiki/EJB3relationships (see the end of the article)

                            Best regards

                            Wolfgang