title: Hibernate throws StreamCorruptedException: invalid stream header
body: <p>I have a class like this,</p>
  
  <pre><code>class SampleClass implements Serializable {
      String name;
      Serializable fieldName;
  }
  </code></pre>
  
  <p>And another class like,</p>
  
  <pre><code>class AnotherClass implements Serializable {
      SampleClass sampleClass;
  }
  </code></pre>
  
  <p>where both class has their getter and setter methods.</p>
  
  <p>In the main class, I'm getting the <code>sampleClass</code> variable from getter function, and trying to use the <code>sampleClass</code> objects. But when I'm using that, I encounter the error like, <code>could not deserialize</code>.</p>
  
  <p>How to access the members of <code>SampleClass</code>, or shall we have field members of type <code>Serializable</code> ?</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>Edited:
  I am using hibernate, which uses many to one relation between aemploye and aaddress tables.</p>
  
  <p>I created the Hibernate configuration file, and Reverse engineering file in net beans, for the above two tables.</p>
  
  <p>Then I generated the POJO class.</p>
  
  <p>The class and xml are: </p>
  
  <p><code>Aaddress.hbm.xml</code></p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="hibernatetutor.tablebeans.Aaddress" table="aaddress" schema="public"&gt;
      &lt;id name="sno" type="int"&gt;
          &lt;column name="sno" /&gt;
          &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;property name="street" type="serializable"&gt;
          &lt;column name="street" /&gt;
      &lt;/property&gt;
      &lt;set name="aemployes" inverse="true"&gt;
          &lt;key&gt;
              &lt;column name="address" /&gt;
          &lt;/key&gt;
          &lt;one-to-many class="hibernatetutor.tablebeans.Aemploye" /&gt;
      &lt;/set&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p><code>Aemploye.hbm.xml</code></p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="hibernatetutor.tablebeans.Aemploye" table="aemploye" schema="public"&gt;
      &lt;id name="id" type="int"&gt;
          &lt;column name="id" /&gt;
          &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;many-to-one name="aaddress" class="hibernatetutor.tablebeans.Aaddress" fetch="select"&gt;
          &lt;column name="address" /&gt;
      &lt;/many-to-one&gt;
      &lt;property name="name" type="string"&gt;
          &lt;column name="name" /&gt;
      &lt;/property&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p><code>Aaddress.java</code></p>
  
  <pre><code>public class Aaddress implements java.io.Serializable {
  
      private int sno;
      private Serializable street;
      private Set aemployes = new HashSet(0);
  
      public int getSno() {
          return this.sno;
      }
  
      public void setSno(int sno) {
          this.sno = sno;
      }
  
      public Serializable getStreet() {
          return this.street;
      }
  
      public void setStreet(Serializable street) {
          this.street = street;
      }
  
      public Set getAemployes() {
          return this.aemployes;
      }
  
      public void setAemployes(Set aemployes) {
          this.aemployes = aemployes;
      }
  }
  </code></pre>
  
  <p><code>Aemploye.java</code></p>
  
  <pre><code>public class Aemploye implements java.io.Serializable {
  
      private int id;
      private Aaddress aaddress;
      private String name;
  
      public int getId() {
          return this.id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public Aaddress getAaddress() {
          return this.aaddress;
      }
  
      public void setAaddress(Aaddress aaddress) {
          this.aaddress = aaddress;
      }
  
      public String getName() {
          return this.name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p><code>Main.java</code></p>
  
  <pre><code>private void getData() {
      Session session = HibernateUtils.getInstance().openSession();
      Query query = session.createQuery("from Aemploye where id=:id");
      query.setParameter("id", 1);
      Aemploye a = (Aemploye) query.uniqueResult();
      Aaddress a1 = a.getAaddress();
      System.out.println(a1.getStreet());
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>org.hibernate.type.SerializationException: could not deserialize
      at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:217)
      at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:240)
      at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:82)
      at org.hibernate.type.SerializableType.get(SerializableType.java:39)
      at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
      at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
      at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
      at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
      at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
      at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
      at org.hibernate.loader.Loader.getRow(Loader.java:1206)
      at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
      at org.hibernate.loader.Loader.doQuery(Loader.java:701)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
      at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
      at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
      at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
      at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
      at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
      at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
      at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
      at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
      at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
      at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
      at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
      at hibernatetutor.tablebeans.Aaddress$$EnhancerByCGLIB$$44bec229.getStreet(&lt;generated&gt;)
      at hibernatetutor.Main.getData(Main.java:33)
      at hibernatetutor.Main.main(Main.java:24)
  Caused by: java.io.StreamCorruptedException: invalid stream header
      at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:753)
      at java.io.ObjectInputStream.&lt;init&gt;(ObjectInputStream.java:268)
      at org.hibernate.util.SerializationHelper$CustomObjectInputStream.&lt;init&gt;(SerializationHelper.java:252)
      at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209)
      ... 29 more
  </code></pre>