title: getting "Cannot serialize session attribute" after upgrading Hibernate
body: <p>I had to upgrade Spring framework and this also required upgrading Hibernate.</p>
  
  <p>Upgrading Hibernate, broke 3 class files where I was using:</p>
  
  <pre><code>Session session = getSession();
  releaseSession(session);
  </code></pre>
  
  <p>I replaced the above code with:</p>
  
  <pre><code>/** added this **/
  SessionFactory sessionFactory = new configuration().configure().buildSessionFactory();
  /** added this **/
  Session session = sessionFactory.openSession();
  Session session = sessionFactory.openSession();
  session.beginTransaction();
  
  Query query = session.createQuery(sbQuery.toString());
  
  session.getTransaction().commit();
  session.flush();
  /** added this **/
  session.close();
  </code></pre>
  
  <p>And I made all 3 of those classes <code>implements java.io.Serializable</code>
  Because I thought that would fix my problem..</p>
  
  <p>Now when I try to login to my application, it is just hanging...and hanging and doing nothing.</p>
  
  <p>The only thing that I see is what's in my <code>localhost.log</code> file:</p>
  
  <pre><code>Mar 03, 2015 2:12:02 PM org.apache.catalina.session.StandardSession writeObject
  WARNING: Cannot serialize session attribute tmp for session EC6CAD4AE76D6A9202FB91D01EA9A7EF
  java.io.NotSerializableException: com.mchange.v2.c3p0.impl.NewProxyStatement
      at java.io.ObjectOutputStream.writeObject0(Unknown Source)
      at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
      at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
      at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
      at java.io.ObjectOutputStream.writeObject0(Unknown Source)
      at java.io.ObjectOutputStream.writeObject(Unknown Source)
      at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1695)
      at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:1101)
      at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:430)
      at org.apache.catalina.session.StandardManager.unload(StandardManager.java:351)
      at org.apache.catalina.session.StandardManager.stopInternal(StandardManager.java:516)
      at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
      at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5683)
      at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
      at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1591)
      at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1580)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  
  Mar 03, 2015 2:12:02 PM org.apache.catalina.session.StandardSession writeObject
  WARNING: Cannot serialize session attribute ssb for session EC6CAD4AE76D6A9202FB91D01EA9A7EF
  java.io.NotSerializableException: org.apache.catalina.session.StandardSessionFacade
      at java.io.ObjectOutputStream.writeObject0(Unknown Source)
  ... same error code ...
  
  Mar 03, 2015 2:12:02 PM org.apache.catalina.session.StandardSession writeObject
  WARNING: Cannot serialize session attribute db for session EC6CAD4AE76D6A9202FB91D01EA9A7EF
  java.io.NotSerializableException: com.mchange.v2.c3p0.impl.NewProxyStatement
      at java.io.ObjectOutputStream.writeObject0(Unknown Source)
  ... same error code ...
  </code></pre>
  
  <p>updated:</p>
  
  <p>hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.SQLServerDialect&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;net.sourceforge.jtds.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:jtds:sqlserver://localhost/db&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;sa&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;password&lt;/property&gt;
          &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
          &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt; 
          &lt;property name="hibernate.cache.use_second_level_cache"&gt;false&lt;/property&gt;        
          &lt;property name="hibernate.c3p0.min_size"&gt;4&lt;/property&gt;   
          &lt;property name="hibernate.c3p0.max_size"&gt;10&lt;/property&gt;  
          &lt;property name="hibernate.c3p0.timeout"&gt;600&lt;/property&gt;  
          &lt;property name="hibernate.c3p0.max_statements"&gt;25&lt;/property&gt;    
          &lt;property name="hibernate.c3p0.testConnectionOnCheckout"&gt;false&lt;/property&gt;   
          &lt;mapping resource="mil/dla/daps/model/businessobject/login/Address.hbm.xml"/&gt;
          &lt;mapping resource="mil/dla/daps/model/businessobject/login/State.hbm.xml"/&gt;
          &lt;mapping resource="mil/dla/daps/model/businessobject/login/User.hbm.xml"/&gt;
          &lt;mapping resource="mil/dla/daps/model/businessobject/login/UserNotes.hbm.xml"/&gt;
          &lt;mapping resource="mil/dla/daps/model/businessobject/login/FundingNotes.hbm.xml"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>One of the above 5 xml files, <code>Address.hbm.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping package="mil.dla.daps.model.businessobject.login"&gt;
      &lt;class name="Address" table="address" dynamic-insert="false" dynamic-update="false" &gt;
          &lt;id name="id" column="id" type="java.lang.Long" unsaved-value="null"&gt;
              &lt;generator class="native"/&gt;
          &lt;/id&gt;
          &lt;property name="address1" type="string" column="address1" length="50"/&gt;
          &lt;property name="address2" type="string" column="address2" length="50"/&gt;
          &lt;property name="address3" type="string" column="address3" length="50"/&gt;
          &lt;property name="address4" type="string" column="address4" length="50"/&gt;
          &lt;property name="address5" type="string" column="address5" length="50"/&gt;
          &lt;property name="city" type="string" column="city" length="30"/&gt;
          &lt;many-to-one name="state" class="State" column="state" fetch="join"/&gt;
          &lt;property name="zipCode" type="string" column="zip_code" length="10"/&gt;
          &lt;property name="oconus" type="boolean" column="oconus"/&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>And piece of Address.java:</p>
  
  <pre><code>package mil.dla.daps.model.businessobject.login;
  
  import java.rmi.dgc.VMID;
  import org.apache.commons.lang.builder.ToStringBuilder;
  
  public class Address implements BusinessObject {
      private VMID guid = new VMID();
      private Long id;
      private String address1;
      private String address2;
      private String address3;
      private String address4;
      private String address5;
      private String city;
      private State state;
      private String zipCode;
      private boolean oconus;
      private boolean modified = false;
  
      public boolean isModified() {
          return modified;
      }
  
      public void setModified(boolean modified) {
          this.modified = modified;
      }
  
      public String getAddress1() {
          return address1;
      }
  
      public void setAddress1(String address1) {
          this.address1 = address1;
      }
  
      public String getAddress2() {
          return address2;
      }
  
      public void setAddress2(String address2) {
          this.address2 = address2;
      }
  ...
  }
  </code></pre>