-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: SerializationException: could not deserialize
PostPosted: Sun Feb 01, 2004 3:44 am 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
I'm very new to Hibernate, so please forgive me if this is an elementary problem (I actually kind of hope it is).

I have a table called RES_RESOURCE with 4 records stored in a MySQL database. RES_RESOURCE has 2 foreign keys, RES_INL_CODE, RES_INC_CODE . My XML mapping file for RES_RESOURCE is as follows:


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="myclass.db.dao.Res" table="RES_RESOURCE">

<!-- Map columns -->
<!-- Unique id to be used as a type of Primary Key -->
<id name="Uid" type="long" unsaved-value="null">
<column name="RES_UID" sql-type="numeric(8)" not-null="true"/>
<generator class="increment"/>
</id>
<property name="Id" type="java.lang.String">
<column name="RES_ID" sql-type="varchar(10)" not-null="false"/>
</property>

<property name="InlCode" type="myclass.db.dao.Inl">
<column name="RES_INL_CODE" sql-type="varchar(2)" not-null="false"/>
</property>

<property name="IncCode" type="myclass.db.dao.Inc">
<column name="RES_INC_CODE" sql-type="varchar(2)" not-null="false"/>
</property>

<property name="VerCode" type="myclass.db.dao.Ver">
<column name="RES_VER_CODE" sql-type="varchar(12)" not-null="false"/>
</property>

<property name="Revision" type="long">
<column name="RES_REVISION" sql-type="numeric(2)" not-null="false"/>
</property>

<property name="Value" type="java.lang.String">
<column name="RES_VALUE" sql-type="varchar(2000)" not-null="false"/>
</property>

</class>
</hibernate-mapping>


I have written a very simple JUnit test that tries to go through Hibernate to access the DB to get an object back. When I try to run the test, I get a "net.sf.hibernate.SerializationException: could not deserialize" error. Further down the stack trace, it says that it is caused by "java.io.StreamCorruptedException: invalid stream header". The stack trace is included below:



Hibernate: select this.RES_UID as RES_UID0_, this.RES_ID as RES_ID0_, this.RES_INL_CODE as RES_INL_3_0_, this.RES_INC_CODE as RES_INC_4_0_, this.RES_VER_CODE as RES_VER_5_0_, this.RES_REVISION as RES_REVI6_0_, this.RES_VALUE as RES_VALUE0_ from RES_RESOURCE this where this.RES_UID=?
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.type.AbstractType.hydrate(AbstractType.java:66)
at net.sf.hibernate.loader.Loader.hydrate(Loader.java:606)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:547)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:506)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:421)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:204)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:128)
at net.sf.hibernate.loader.Loader.list(Loader.java:918)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:109)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3438)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)
at net.sf.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:322)
at com.transworldhealth.middletier.ORMap.getResource(ORMap.java:62)
at com.transworldhealth.middletier.ResourceMgr.getResource(ResourceMgr.java:92)
at com.transworldhealth.middletier.HibernateTest.testHibernateGetObject(HibernateTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:397)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:281)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:173)
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)
... 35 more



Does anybody have any idea what's going on and how I can fix it? I've already spent the better part of a day and a half researching and trying to understand this problem. If anyone could help, it would really be appreciated!

Thanks in advance,

ccrupper


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 01, 2004 9:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
type="myclass.db.dao.Ver" whats this? Is Ver really a custom user type? If not, you should use associations like one-to-one or one-to-many for this.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 01, 2004 5:02 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
the type="myclass.db.dao.Ver" is a custom user type. In the Java code, we're using Ver (and Inl and Inc) as objects where we use the java object's accessors methods to get and set the various attributes.

Here's an example of what I mean:

public static Resource getResource(Res a_res, String as_resourceId, String as_lang, String as_country, Session a_session)
throws HibernateException, SystemException {
Resource l_resourceObject = null;

try {
Criteria l_criteria = a_session.createCriteria(Res.class);
l_criteria.add(Expression.eq("Uid", new Long(2)));
// l_criteria.add(Expression.eq("Id", as_resourceId));
// l_criteria.add(Expression.eq("InlCode", as_lang));
// l_criteria.add(Expression.eq("IncCode", as_country));
Res l_res =(Res) l_criteria.uniqueResult();
if (l_res != null) {
l_resourceObject = new Resource("M", l_res.getInlCode().getCode(), l_res.getIncCode().getCode(),
l_res.getId(), l_res.getVerCode().getCode(), l_res.getRevision(), l_res.getValue());
}
} catch (HibernateException e) {
e.printStackTrace();
throw new SystemException(new Resource ("M", "EN", "US", "HIB", "1", 1, "Error fetching Resource from Hibernate"),
null, e);
}

return l_resourceObject;


Essentially, I'd like to be using the 3 lines that are commented out and get rid of the one line that is above them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 01, 2004 8:11 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
Your suggestion worked gloeglm. Using the many-to-one mappings was exactly what I needed to do. Thank you very much!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.