alikoank
asked on
net.sf.hibernate.type.SerializationException: could not deserialize
hi experts,
when I try to select a row from database using hibernate I get the net.sf.hibernate.type.Seri alizationE xception: could not deserialize exception. When I try to fetch a row it returns a null value normally but it cannot "deserialize" exiting data into a class. All my classes implement Serializable.
the part where I do the operation is here:
try {
session = openSession();
Query q = session.createQuery("fromX xxDTO d where d.xno = :xno");
q.setParameter("xno",xNo);
result = (XxxDTO) q.uniqueResult();
} catch (HibernateException ex) {
log.error("hibernate error", ex);
throw new DAOException("hibernate error:" + ex.toString());
} finally {
closeSession(session);
}
Here is the full text of exception.
net.sf.hibernate.type.Seri alizationE xception: could not deserialize
at net.sf.hibernate.util.Seri alizationH elper.dese rialize(Se rializatio nHelper.ja va:197)
at net.sf.hibernate.util.Seri alizationH elper.dese rialize(Se rializatio nHelper.ja va:220)
at net.sf.hibernate.type.Seri alizableTy pe.fromByt es(Seriali zableType. java:73)
at net.sf.hibernate.type.Seri alizableTy pe.get(Ser ializableT ype.java:3 8)
at net.sf.hibernate.type.Null ableType.n ullSafeGet (NullableT ype.java:6 2)
at net.sf.hibernate.type.Null ableType.n ullSafeGet (NullableT ype.java:5 3)
at net.sf.hibernate.type.Abst ractType.h ydrate(Abs tractType. java:66)
at net.sf.hibernate.loader.Lo ader.hydra te(Loader. java:680)
at net.sf.hibernate.loader.Lo ader.loadF romResultS et(Loader. java:621)
at net.sf.hibernate.loader.Lo ader.insta nceNotYetL oaded(Load er.java:58 0)
at net.sf.hibernate.loader.Lo ader.getRo w(Loader.j ava:495)
at net.sf.hibernate.loader.Lo ader.prepa reResultSe tRow(Loade r.java:209 )
at net.sf.hibernate.loader.Lo ader.doQue ry(Loader. java:282)
at net.sf.hibernate.loader.Lo ader.doQue ryAndIniti alizeNonLa zyCollecti ons(Loader .java:133)
at net.sf.hibernate.loader.Lo ader.doLis t(Loader.j ava:1027)
at net.sf.hibernate.loader.Lo ader.list( Loader.jav a:1018)
at net.sf.hibernate.hql.Query Translator .list(Quer yTranslato r.java:854 )
at net.sf.hibernate.impl.Sess ionImpl.fi nd(Session Impl.java: 1544)
at net.sf.hibernate.impl.Quer yImpl.list (QueryImpl .java:39)
at net.sf.hibernate.impl.Abst ractQueryI mpl.unique Result(Abs tractQuery Impl.java: 550)
at com.tsk.beyanname.dao.hibe rnate.this .findByTcK imlikNo(th is.java:32 )
at test.tsk.beyanname.dao.hib ernate.Tes tThis.test FindByTcKi mlikNo(Tes tThis.java :37)
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Na tiveMethod AccessorIm pl.java:39 )
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Delegati ngMethodAc cessorImpl .java:25)
at java.lang.reflect.Method.i nvoke(Meth od.java:32 4)
at junit.framework.TestCase.r unTest(Tes tCase.java :154)
at junit.framework.TestCase.r unBare(Tes tCase.java :127)
at junit.framework.TestResult $1.protect (TestResul t.java:106 )
at junit.framework.TestResult .runProtec ted(TestRe sult.java: 124)
at junit.framework.TestResult .run(TestR esult.java :109)
at junit.framework.TestCase.r un(TestCas e.java:118 )
at junit.framework.TestSuite. runTest(Te stSuite.ja va:208)
at junit.framework.TestSuite. run(TestSu ite.java:2 03)
at junit.framework.TestSuite. runTest(Te stSuite.ja va:208)
at junit.framework.TestSuite. run(TestSu ite.java:2 03)
at com.borland.jbuilder.unitt est.JBTest Runner.run (JBTestRun ner.java:2 10)
at com.borland.jbuilder.unitt est.JBTest Runner.ini tiateTest( JBTestRunn er.java:25 2)
at com.borland.jbuilder.unitt est.JBTest Runner.mai n(JBTestRu nner.java: 558)
Caused by: java.io.StreamCorruptedExc eption: invalid stream header
at java.io.ObjectInputStream. readStream Header(Obj ectInputSt ream.java: 737)
at java.io.ObjectInputStream. <init>(Obj ectInputSt ream.java: 253)
at net.sf.hibernate.util.Seri alizationH elper.dese rialize(Se rializatio nHelper.ja va:189)
... 38 more
any ideas?
when I try to select a row from database using hibernate I get the net.sf.hibernate.type.Seri
the part where I do the operation is here:
try {
session = openSession();
Query q = session.createQuery("fromX
q.setParameter("xno",xNo);
result = (XxxDTO) q.uniqueResult();
} catch (HibernateException ex) {
log.error("hibernate error", ex);
throw new DAOException("hibernate error:" + ex.toString());
} finally {
closeSession(session);
}
Here is the full text of exception.
net.sf.hibernate.type.Seri
at net.sf.hibernate.util.Seri
at net.sf.hibernate.util.Seri
at net.sf.hibernate.type.Seri
at net.sf.hibernate.type.Seri
at net.sf.hibernate.type.Null
at net.sf.hibernate.type.Null
at net.sf.hibernate.type.Abst
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.loader.Lo
at net.sf.hibernate.hql.Query
at net.sf.hibernate.impl.Sess
at net.sf.hibernate.impl.Quer
at net.sf.hibernate.impl.Abst
at com.tsk.beyanname.dao.hibe
at test.tsk.beyanname.dao.hib
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at junit.framework.TestCase.r
at junit.framework.TestCase.r
at junit.framework.TestResult
at junit.framework.TestResult
at junit.framework.TestResult
at junit.framework.TestCase.r
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at junit.framework.TestSuite.
at com.borland.jbuilder.unitt
at com.borland.jbuilder.unitt
at com.borland.jbuilder.unitt
Caused by: java.io.StreamCorruptedExc
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at net.sf.hibernate.util.Seri
... 38 more
any ideas?
Does "XxxDTO" implement Serializable?
Ahhh...sorry...didn't read the question properly ;-)
Is this right:
Query q = session.createQuery("fromX xxDTO d where d.xno = :xno");
Shouldn't it be:
Query q = session.createQuery("from XxxDTO as d where d.xno = :xno");
Query q = session.createQuery("fromX
Shouldn't it be:
Query q = session.createQuery("from XxxDTO as d where d.xno = :xno");
I always use fully qualified classnames in the queries....not sure if that helps:
Query q = session.createQuery( "from org.your.package.XxxDTO as d where d.xno = :xno");
Query q = session.createQuery( "from org.your.package.XxxDTO as d where d.xno = :xno");
If the query doesn't normally return a unique result, try just operating on the first one instead of calling uniqueResult
ASKER
@TimYates
its just a typo I am not getting SQL Exceptions :-) and giving fully qualified name has not changed anything.
@CEHJ
using q.list() instead of q.uniqueResult() gave me an empty list when it should contain one XxxDTO.
its just a typo I am not getting SQL Exceptions :-) and giving fully qualified name has not changed anything.
@CEHJ
using q.list() instead of q.uniqueResult() gave me an empty list when it should contain one XxxDTO.
> at com.tsk.beyanname.dao.hibe rnate.this .findByTcK imlikNo(th is.java:32 )
Which line is line 32?
Which line is line 32?
I guess: result = (XxxDTO) q.uniqueResult();
Does list() throw the exception?
Does list() throw the exception?
ASKER
32: throw new DAOException("hibernate error:" + ex.toString());
ASKER
and yes list() throws the exception too
>>using q.list() instead of q.uniqueResult() gave me an empty list when it should contain one XxxDTO.
I can't think how you can get anything more than null back then, if you get an empty list without the uniqueness
I can't think how you can get anything more than null back then, if you get an empty list without the uniqueness
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> Are you sure that the same version of XxxDTO exists in hibernate and your client?
I meant:
Are you sure that the same version of XxxDTO.class exists in hibernate and your client? Compiled with the same JDK?
I meant:
Are you sure that the same version of XxxDTO.class exists in hibernate and your client? Compiled with the same JDK?
ASKER
ok. guys thank for your effort. it probably has something to do with mu mapping
8-)
ASKER
yep. I solved it,
I had declared a many-to-one relation as a property in hbm file.
I had declared a many-to-one relation as a property in hbm file.
Cool :-)
After a week of trying hibernate/jboss/xdoclet out, I have to say that the Hibernate exceptions could be a little bit more descriptive ;-)
Good luck with it :-)
Tim
After a week of trying hibernate/jboss/xdoclet out, I have to say that the Hibernate exceptions could be a little bit more descriptive ;-)
Good luck with it :-)
Tim
ASKER
>> Hibernate exceptions could be a little bit more descriptive ;-)
could not agree more.
could not agree more.
Glad you got it fixed