Hi,
I have a simple one-to-many relationship that I want to map, but getting SerializationException;
My code Looks like this:
Session sess = getHibernateSession();
List resultList = null;
try {
Criteria crit = sess.createCriteria(ItemGroup.class);
resultList = crit.list();
} catch (HibernateException e) {
throw new DaoException("Error Creating Query: getDataOBjects(Query)" + dataObjectClass, e);
} finally {
closeHibernateSession();
}
My mapping looks like this:
<hibernate-mapping>
<class name="ItemGroup" table="item_master">
<id name="itemMasterId" column="item_master_id">
<generator class="assigned"/>
</id>
<one-to-one name="itemGroupRelation" class="ItemGroupRelation"
cascade="all" property-ref="childItemId" />
<map name="childGroupRelationMap" table="item_group" cascade="all-delete-orphan">
<key column="parent_item_master_id"/>
<index column="child_item_master_id" type="integer"/>
<element column="top_parent_item_master_id" type="ItemGroupRelation"/>
</map>
</class>
<class name="ItemGroupRelation" table="item_group">
<id name="groupRelationId" column="item_group_id">
<generator class="native"/>
</id>
<property name="childItemId" column="child_item_master_id"/>
<property name="parentItemId" column="parent_item_master_id"/>
<property name="topParentItemId" column="top_parent_item_master_id"/>
</class>
</hibernate-mapping>
I am getting no error when there are no Children to load i.e. when there are no elements to load into the map. But, if a particular row in item_master has children in item_group table, then getting the following error:
Caused by: net.sf.hibernate.type.SerializationException: could not deserialize
at net.sf.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:197)
at net.sf.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:220)
at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:73)
at net.sf.hibernate.type.SerializableType.get(SerializableType.java:38)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:363)
at net.sf.hibernate.collection.Map.readFrom(Map.java:200)
at net.sf.hibernate.loader.Loader.readCollectionElement(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:219)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:910)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:885)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:69)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3226)
at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:340)
at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3089)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
at net.sf.hibernate.loader.Loader.list(Loader.java:941)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3571)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:223)
at com.vizional.vizid.dao.hibernate.HibernateDao.getDataObjects(HibernateDao.java:138)
... 1 more
Caused by: java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
at net.sf.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:189)
... 25 more
What am I missing..
Thanks
|