I am presently writing something to plug into a current enterprise application that utilizes Hibernate. My tool at install time must write some values in to the database where among the posts is really a serialized version of the setting descriptor object. This object has two lists of objects along with a couple of primitive types.

My current approach is to produce a ByteArrayOutputStream as well as an ObjectOutputStream after which write the ObjectOutputStream towards the ByteArrayOutputStream, then passing the resulting byte array in to the sql with Spring's 1SimpleJdbcTemplate1. My current problem with this particular approach is the fact that once the enterprise tool pulls my rows it does not p-serialze the column using the following:

org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize

Personally i think I might need to serialize the interior objects, but have no idea how to achieve that and everything together.

Wound up fixing my very own problem. Within the hibernate API there's a category known as SerializationHelper which has a static function serialize(Serializable obj) that we could use to serialize my object after which place it in to the database. Hibernate ended up being in a position to see clearly within the enterprise application.

You are able to serealize a Java object into bytes after which store it inside a BLOB.


ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
byte[] bytes = byteOut.toByteArray()


 public <T extends Serializable> T getObject(Class<T> type) throws IOException, ClassNotFoundException{
        if(bytes == null){
            return null;
        ByteArrayInputStream byteIn = new ByteArrayInputStream(bytes);
        ObjectInputStream in = new ObjectInputStream(byteIn);
        T obj = (T) in.readObject();
        return obj;