-->
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.  [ 13 posts ] 
Author Message
 Post subject: Serious serialization issue with hibernate
PostPosted: Fri Sep 12, 2003 10:23 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Winth hibernate 2.0 we started saving some data in the database as a serialized object using

<property name="notes" column="notes" type="serializable"/>

Suddenly with release 2.02 we started getting

net.sf.hibernate.type.SerializationException: Could not deserialize a serializable property:
at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:75)
at net.sf.hibernate.type.SerializableType.get(SerializableType.java:35)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:60)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:51)
at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
at net.sf.hibernate.loader.Loader.hydrate(Loader.java:494)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:448)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:417)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:356)
at net.sf.hibernate.loader.Loader.doResultSet(Loader.java:190)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:113)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:661)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:676)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:52)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:44)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:378)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2059)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1913)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1839)


When trying to load our classes. The same happens with version 2.1. It appears that hibernate uses some serialization wrapper whose serial version number has changed. We have tens of thousands of record that can not be read with newer version of hibernate. This of serious concern for us as we need some of hibernate's newer features.

Does anyone have a possible solution? I was going to raise this as an issue in JIRA but i don't know if it would get fixed. Any comments?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 10:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Are you telling me you serialized objects to the database that included Hibernate collection wrappers or something?! Thats the only thing I can think of that would cause this.

Shit thats dangerous. I suggest you reconsider this design! Anyway, your data is safe; you can always write a little piece of code that loads the objects in 2.0 and then translates them into something else with no Hibernate classes.

So don't stress, I'll help you get this sorted...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 11:12 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
The notes class that gets serialized is just an ArrayList with some extra validation added. The Note class is a string message with a timestamp. As far as I am aware we never used any wrapper deliberately and assumed that hibernate was storing only a serialized version of Notes.

We are currently thinking of changing the notes field to a clob and having hibernate do the conversion. is this OK?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 11:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ummm we don't do anything "funny" with your object. Perhaps you need to do a little bit more investigation here ... Hibernate has no "wrapper" class.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 12:52 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Ok, looking at this one step at a time.
(I am using the same system to test this tomcat 4.1.24 running on win2k using struts 1.1)

hibernate 2.01 has no problems loading the serialized object.

hibernate 2.02 gives the following exception

java.io.InvalidClassException: net.sf.hibernate.collection.PersistentCollection; local class incompatible: stream classdesc serialVersionUID = 2493596380417783473, local class serialVersionUID = -8318395321868084057
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:463)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at java.util.ArrayList.readObject(ArrayList.java:547)
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 java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:838)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:165)
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:191)
at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:72)
at net.sf.hibernate.type.SerializableType.get(SerializableType.java:35)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:59)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:51)
at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
at net.sf.hibernate.loader.Loader.hydrate(Loader.java:419)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:373)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:342)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:281)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)


This is actually rethrown from org.apache.commons.lang.SerializationUtils.deserialize()

This made me think that perhaps the problem is with commons-lang.jar.
However, keeping all the lib jars from hib2.01 and using hib2.02 reproduced the above exception. While using the lib jars from hib2.02 with hib2.01 did not trigger any exception. I can only conclude that something changed from 2.01 -> 2.02 in hibernate2.jar to cause this.

I think that the persistentCollection class needs to have a serial version id set to its 2.01 value.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yeah, so you serialized a Hibernate PersistentCollection. Urrrghhh. Very Bad.

I do not, and cannot, guarantee that PersistentCollection implementations will be deserializable accross diff versions of Hibernate. Like, I actually change the instance variable from time to time.

I suggest you re-design this ... and then get back to me if you run into problems with either implementing it, or porting the data forward.

Is that cool?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:20 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
let me take a guess - the fact that the class we tried to serialize Notes extends ArrayList, wheras hibernate uses its own versions of Collection has led to this mistake? Hibenate thought Notes was an ArrayList and substituted a PersistentCollection for it?

I guess serves us right for not thinking through the design better. I plan to write some code to get the notes from the db and reinsert them into a new clob field and later change the mapping and class to use strings. Hope it works.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
NO! Hibernate did not screw with your property!

*you* must have done it in the application, by setting the persistent collection to the serializable property!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:40 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
our class Notes extends java.util.ArrayList, it has nothing to do with net.sf.hibernate.collection.PersistentCollection. At least I am unaware how it can be. The mapping to persist it was
<property name="notes" type="serializable"/> which to me suggests that the class Notes would be serialized not PersistentCollection. While I think this was a stupid design decision now it is not obvious to me where the persisten collection enters into the picture.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 1:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are not listening to me.

Listen, when I state something straight out like this, and I am talking about Hibernate, I am always (at least 99.9% of the time) correct!

I am telling you it is NOTHING to do with using an array list.

It is *where you got the list from*! You got it from another persistent object.

It is an error in your application.

Please read things I say and not waste my time by making me type things twice.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 2:21 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Looking over the code there are only two places where notes get created.
When a new customer instance is created it automatically gets an empty new Notes collection. The other place is when a customer instance is loaded from the database and its Notes field is set by hibernate. I assume that it is this that caused the problem as it is the only place wheer persistent collections occur. No other class uses Notes and nowhere else is it set or created.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
well, I'm certain you are mistaken.

Perhaps the things inside this list have a collection. I dunno. But certainly if I persist an object with a list, and then load it back, it comes back as a plain ArrayList.

I invite you to step through the code that persists a SerializableType and verify this for yourself.

If you do new ArrayList() in your code, its an ArrayList, and it stays that way till it hits SerializableType!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 2:55 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Well its late here and I can't see where this would have gone wrong. i will migrate the notes to some other format next week and if i learn anything new I will post it to the forums.

thanks


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