title: How do I Serialize Object to Database for Hibernate to read in Java
body: <p>I'm currently writing a tool to plug into an existing enterprise application that uses Hibernate.  My tool at install time needs to write some values into the database where one of the columns is a serialized version of a setting descriptor object.  This object has two lists of objects and a few primitive types.</p>
  
  <p>My current approach is to create a <code>ByteArrayOutputStream</code> and an <code>ObjectOutputStream</code> and then write the <code>ObjectOutputStream</code> to the <code>ByteArrayOutputStream</code>, then passing the resulting byte array into the sql with Spring's 1SimpleJdbcTemplate1.  My current issue with this approach is that when the enterprise tool pulls my rows it fails to de-serialze the column with the following:</p>
  
  <pre><code>org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize
  </code></pre>
  
  <p>I feel I may need to serialize the inner objects, but have no clue how to do that and keep everything together.  </p>