-->
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.  [ 5 posts ] 
Author Message
 Post subject: SerializationException when doing deserialization with HQSQL
PostPosted: Tue Jul 31, 2007 11:00 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Hi Folks,
I am getting an org.hibernate.type.SerializationException when trying to load an object using Hibernate 3.2.4SP1. I am using HQSQL running as a in-memory database. Mapping where this exception takes place is a simple one-to-one mapping (based on primary key association), as follows:

<one-to-one name="person" class="Person"/>
<one-to-one name="employee" class="Employee" constrained="true"/>
<class name="person" table="PERSON">
<id name="id" column="PERSON_ID">
<generator class="foreign">
<param name="property">employee</param>
</generator>
</id>
...
<one-to-one name="employee"
class="Employee"
constrained="true"/>
</class>

Strangest thing is, when debugging through the code, I can see the rows being returned from database. The exception takes place when hibernate tries to read bytes form the results set which is returned.

Cheers, Mehrzad Karami

Below is a stacktrace. Any help is appreciated.

org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize
Caused by: org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:217)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:240)
at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:82)
at org.hibernate.type.SerializableType.get(SerializableType.java:39)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
.
.
.
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:333)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
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.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:770)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:286)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:252)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209)
... 39 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 11:42 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Do you mean HSQLDB? I'm having no problem running this example on the in-memory database (v1.8.0.7).

The fact you're in SerializationHelper.deserialize means your mapping contains something other than the basic java types. It might help to post your real mapping files and java classes.


Top
 Profile  
 
 Post subject: SerializationException when doing deserialization with HQSQL
PostPosted: Wed Aug 01, 2007 2:32 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Hi,
Below is a detailed mapping model I am using for Person and Employee. I am using more objects in my data model, e.g. there are a couple of more mapping files for my other objects, but these are not having any association with the Person table.
Whenever I had the one-to-one association to Person table in the Employee mapping file, I get the deserialization error. The set definition I am using for the hierarchy policies works fine.

Mapping Employee:
Code:
<hibernate-mapping>
    <class name="com.business.domain.um.Employee" table="employee_user">
        <id name="userID" type="string" column="user_id"/>
   <one-to-one name="person" class="com.business.domain.um.Person"/>
        <set name="hierarchyPolicies" inverse="true" fetch="subselect" lazy="false" cascade="all, delete-orphan">
      <key>
         <column name="user_id" not-null="true"/>
      </key>
      <one-to-many class="com.business.domain.um.HierarchyPolicy" />
      </set>
    </class>
</hibernate-mapping>



Mapping Person:
Code:
<hibernate-mapping>
   <class name="com.cm.business.domain.um.Person" table="user">
      <id name="employee" column="user_id">
         <generator class="foreign">
            <param name="property">employee</param>
         </generator>
      </id>
      <one-to-one name="employee" class="com.cm.business.domain.um.Employee" constrained="true"/>
         <property name="hasBalance" type="boolean" column="has_tb" not-null="true"/>
         </class>
</hibernate-mapping>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 10:14 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
I think the problem is with the Person mapping. You've mapped the id column to employee AND the one-to-one relationship to employee. This might cause Employee instances to be serialized as the Id.

In the hibernate docs their example maps the id with a different property:
Code:
<class name="person" table="PERSON">
<!-- Hibernate docs has "id" here as the name of this property. -->
    <id name="id" column="PERSON_ID">
        <generator class="foreign">
            <param name="property">employee</param>
        </generator>
    </id>
    ...
    <one-to-one name="employee"
        class="Employee"
        constrained="true"/>
</class>


Top
 Profile  
 
 Post subject: SerializationException when doing deserialization with HQSQL
PostPosted: Wed Aug 01, 2007 11:33 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Hi,
Yes, this is how it was implemented in the original example. The only issue is that having an id used in the mapping for Person would mean that this parameter need to be defined as a property in the Person class. Person object would look like the following then:

Code:
Public class Person implements Serializable {
    private String id;
    private Employee employee;
    private boolean hasBalance;

...... (getters and setters go here)

Public class Employee implements Serializable {
    private String id;
    private set hierarchyPolicies;

.....(getters and setters go here)


Even though person.id refers to the same id as person.employee.id I would need to (re)define it as a property in Person. It just seems odd to me to keep an extra property in Person just in order to get the mapping correct, since I can just use delegation Java in order to get my id from the employee object (person.getEmployee().getID())

It can be that I am wrong about the usage of one-to-one mapping here, but my first assumption was that mapping Person and Employee through the one-to-one mapping based on Primary Key would not require adding a new property in Person. All I need is to define a one-to-one mapping between Person and Employee based on the Primay key. In other words:

Code:
create table employee(
id VARCHAR(10) NOT NULL,
PRIMARY KEY(ID);
);

create table person(
id VARCHAR(10) NOT NULL,
PRIMARY KEY(ID);
FOREIGN KEY(ID)
    REFERENCES employee(id)
       ON DELETE NO ACTION
       ON UPDATE NO ACTION
);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.