title: How to deal with postgresql data types that Hibernate can not deserialize?
body: <p>I recently started attempting to use hibernate to interact with my database.  I was following a guide I found online to set it up and use it.</p>
  
  <p><a href="https://netbeans.org/kb/docs/java/hibernate-java-se.html" rel="nofollow">https://netbeans.org/kb/docs/java/hibernate-java-se.html</a></p>
  
  <p>Everything seemed to work ok until I tried to run a query on tables that contained postgresql datatypes such as Polygon and Pointz.</p>
  
  <p>In my .java classes that are generated by the reverse engineering of the tables for these postgresql data types it list the types as Serializable.  </p>
  
  <pre><code> public class Activity  implements java.io.Serializable {
  
  
   private long id;
   private ActivityType activityType;
   private WorkflowAnalyticInstance workflowAnalyticInstance;
   private Producer producer;
   private String activityUuid;
   private Serializable spatialBounds;
   private Long startTime;
   private Long endTime;
   private Double probability;
   private float protoVersion;
   private String protoLocation;
   private Date lastModified;
   private Set anomalyToActivityMappings = new HashSet(0);
   private Set activityToEventMappings = new HashSet(0);
   private Set activityToTrackIntervalMappings = new HashSet(0);
  
  public Activity() {
  }
  
  
  public Activity(long id, ActivityType activityType, WorkflowAnalyticInstance workflowAnalyticInstance, Producer producer, float protoVersion) {
      this.id = id;
      this.activityType = activityType;
      this.workflowAnalyticInstance = workflowAnalyticInstance;
      this.producer = producer;
      this.protoVersion = protoVersion;
  }
  public Activity(long id, ActivityType activityType, WorkflowAnalyticInstance workflowAnalyticInstance, Producer producer, String activityUuid, Serializable spatialBounds, Long startTime, Long endTime, Double probability, float protoVersion, String protoLocation, Date lastModified, Set anomalyToActivityMappings, Set activityToEventMappings, Set activityToTrackIntervalMappings) {
     this.id = id;
     this.activityType = activityType;
     this.workflowAnalyticInstance = workflowAnalyticInstance;
     this.producer = producer;
     this.activityUuid = activityUuid;
     this.spatialBounds = spatialBounds;
     this.startTime = startTime;
     this.endTime = endTime;
     this.probability = probability;
     this.protoVersion = protoVersion;
     this.protoLocation = protoLocation;
     this.lastModified = lastModified;
     this.anomalyToActivityMappings = anomalyToActivityMappings;
     this.activityToEventMappings = activityToEventMappings;
     this.activityToTrackIntervalMappings = activityToTrackIntervalMappings;
  }
  }
  </code></pre>
  
  <p>When I run my queries on tables that contain these types of data types I get the following error:</p>
  
  <p>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.doList(Loader.java:2220)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
      at org.hibernate.loader.Loader.list(Loader.java:2099)
      at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912)
      at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
  Caused by: java.io.StreamCorruptedException: invalid stream header: 30313033
      at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:802)
      at java.io.ObjectInputStream.(ObjectInputStream.java:299)
      at org.hibernate.util.SerializationHelper$CustomObjectInputStream.(SerializationHelper.java:252)
      at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209)
      ... 22 more</p>
  
  <p>So how do you deal with these postgres data types that can not be deserialized?</p>