Solved

net.sf.hibernate.type.SerializationException: could not deserialize

Posted on 2004-09-14
20
2,285 Views
Last Modified: 2012-05-05
hi experts,

when I try to select a row from database using hibernate I get the net.sf.hibernate.type.SerializationException: 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("fromXxxDTO 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.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:680)
      at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:621)
      at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:580)
      at net.sf.hibernate.loader.Loader.getRow(Loader.java:495)
      at net.sf.hibernate.loader.Loader.prepareResultSetRow(Loader.java:209)
      at net.sf.hibernate.loader.Loader.doQuery(Loader.java:282)
      at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
      at net.sf.hibernate.loader.Loader.doList(Loader.java:1027)
      at net.sf.hibernate.loader.Loader.list(Loader.java:1018)
      at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
      at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
      at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
      at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:550)
      at com.tsk.beyanname.dao.hibernate.this.findByTcKimlikNo(this.java:32)
      at test.tsk.beyanname.dao.hibernate.TestThis.testFindByTcKimlikNo(TestThis.java:37)
      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 junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at com.borland.jbuilder.unittest.JBTestRunner.run(JBTestRunner.java:210)
      at com.borland.jbuilder.unittest.JBTestRunner.initiateTest(JBTestRunner.java:252)
      at com.borland.jbuilder.unittest.JBTestRunner.main(JBTestRunner.java:558)
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)
      ... 38 more

any ideas?
0
Comment
Question by:alikoank
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 5
20 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12053554
Does "XxxDTO" implement Serializable?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12053556
Ahhh...sorry...didn't read the question properly ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12053560
Is this right:

      Query q = session.createQuery("fromXxxDTO d where d.xno = :xno");

Shouldn't it be:

      Query q = session.createQuery("from XxxDTO as d where d.xno = :xno");
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 35

Expert Comment

by:TimYates
ID: 12053567
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");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12053580
If the query doesn't normally return a unique result, try just operating on the first one instead of calling uniqueResult
0
 
LVL 4

Author Comment

by:alikoank
ID: 12053670
@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.

0
 
LVL 35

Expert Comment

by:TimYates
ID: 12053698
>     at com.tsk.beyanname.dao.hibernate.this.findByTcKimlikNo(this.java:32)
 
Which line is line 32?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12053703
I guess: result = (XxxDTO) q.uniqueResult();

Does list() throw the exception?
0
 
LVL 4

Author Comment

by:alikoank
ID: 12053730
32: throw new DAOException("hibernate error:" + ex.toString());
0
 
LVL 4

Author Comment

by:alikoank
ID: 12053736
and yes list() throws the exception too
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12053737
>>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
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 12053743
Might be worth checking that your mapping is correct
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 250 total points
ID: 12053765
Are you sure that the same version of XxxDTO exists in hibernate and your client?

This is a confusing error :-(

I guess it is getting null back as it is failing with a SerializationException...  Which implies it is trying to return something, but it cannot deserialize it...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12053772
>  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?
0
 
LVL 4

Author Comment

by:alikoank
ID: 12053778
ok. guys thank for your effort. it probably has something to do with mu mapping
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12053921
8-)
0
 
LVL 4

Author Comment

by:alikoank
ID: 12054351
yep. I solved it,
I had declared a many-to-one relation as a property in hbm file.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12054418
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
0
 
LVL 4

Author Comment

by:alikoank
ID: 12054543
>>  Hibernate exceptions could be a little bit more descriptive ;-)

could not agree more.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12054552
Glad you got it fixed
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question