我最近开始尝试使用hibernate与我的数据库进行交互。我正在按照我在网上找到的指南进行设置并使用它。
https://netbeans.org/kb/docs/java/hibernate-java-se.html
在我尝试对包含postgresql数据类型(如Polygon和Pointz)的表运行查询之前,似乎一切正常。
在我对这些postgresql数据类型的表的逆向工程生成的.java类中,它将类型列为Serializable。
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;
}
}
当我对包含这些类型的数据类型的表运行查询时,我收到以下错误:
org.hibernate.type.SerializationException:无法反序列化 在org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:217) 在org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:240) at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:82) 在org.hibernate.type.SerializableType.get(SerializableType.java:39) 在org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163) 在org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154) 在org.hibernate.type.AbstractType.hydrate(AbstractType.java:81) 在org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096) 在org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380) 在org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308) 在org.hibernate.loader.Loader.getRow(Loader.java:1206) 在org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580) 在org.hibernate.loader.Loader.doQuery(Loader.java:701) 在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) 在org.hibernate.loader.Loader.doList(Loader.java:2220) 在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) 在org.hibernate.loader.Loader.list(Loader.java:2099) 在org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912) 在org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172) 在org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121) 在org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) 引起:java.io.StreamCorruptedException:无效的流标题:30313033 at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:802) 在java.io.ObjectInputStream。(ObjectInputStream.java:299) at org.hibernate.util.SerializationHelper $ CustomObjectInputStream。(SerializationHelper.java:252) 在org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209) ......还有22个
那么你如何处理这些无法反序列化的postgres数据类型呢?