I have a simple example working with postgres 8.4 & Hibernate 3 (driven by integration with a third party application). I can read limited records (not including uuid fields), but when I add the mapping for the uuid field (Id below), my code generates the following exception:
org.hibernate.type.SerializationException: could not deserialize ... Caused by: java.io.StreamCorruptedException: invalid stream header ...
The records read OK, but they do not serialize (the exception is thrown in the records.add(iter.next()) line of code near the bottom below). Does anyone know what I may be missing in order to serialize the postgres uuid fields into Java UUID objects?
Component.java: =================================================== package com.test.persist; import java.util.UUID; public class Component { // extends PersistentMessage { private UUID Id; private String Name; private boolean Connect; private boolean Connected;
public Component() { } public boolean Equals(Object object) { if (object == null || !(object instanceof Component)) return false; Component rhs = (Component) object; return this.hashCode() == rhs.hashCode(); } public int hashCode() { return this.Id.hashCode(); } public String getName() { return Name; } public void setName(String name) { Name = name; } public boolean isConnect() { return Connect; } public void setConnect(boolean connect) { Connect = connect; } public boolean isConnected() { return Connected; } public void setConnected(boolean connected) { Connected = connected; } public UUID getId() { return Id; } public void setId(UUID id) { Id = id; } }
hibernate.cfg.xml: =================================================== <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> <property name="hibernate.connection.url">jdbc:postgresql://localhost/nabdb/common</property> <property name="hibernate.connection.username">postgres</property> <property name="hibernate.connection.password">Password12345!</property> <property name="hibernate.connection.pool_size">10</property> <property name="show_sql">false</property> <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="component.hbm.xml"/> </session-factory> </hibernate-configuration>
component.hbm.xml: =================================================== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <typedef name="uuid" class="java.util.UUID"> </typedef> <class name="com.test.persist.Component" table="Component" lazy="false"> <id name="Name" type="string" column="Name"> <generator class="native"/> </id> <property name="Connect" type="boolean"/> <property name="Connected" type="boolean"/> </class> </hibernate-mapping>
DAO code performing the read ("Component" is passed in as the String): ========================== public List findAll(Session session, String type) { String SQL_QUERY = "from " + type; session.beginTransaction(); Query query = session.createQuery(SQL_QUERY); Iterator iter = query.iterate(); List records = new ArrayList(); while (iter.hasNext()) { records.add(iter.next()); } session.getTransaction().commit(); return records; }
|