aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate + An exception occurred: org.hibernate.type.SerializationException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate + An exception occurred: org.hibernate.type.SerializationException" Watch "hibernate + An exception occurred: org.hibernate.type.SerializationException" New topic
Author

hibernate + An exception occurred: org.hibernate.type.SerializationException

sonalika kulkarni
Greenhorn

Joined: Dec 10, 2010
Posts: 16
I in our project we have a refactoring of package structure recently. Now the thing is that we have blobs in the table and templates that refer to earlier package structure. and now its giving SerializationException while reading blob which stores Serialized objects in it. What should be the best way to handle and update this exception?
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

That's exactly why we need to use serialversionUid in our class when we are implementing serialization.
check how we can use serialver command in java. See if that helps.


If you are not laughing at yourself, then you just didn't get the joke.
sonalika kulkarni
Greenhorn

Joined: Dec 10, 2010
Posts: 16
Arun Kumarr wrote:That's exactly why we need to use serialversionUid in our class when we are implementing serialization.

how using serialversionUid can help us in serialization.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

"If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization. Therefore, to guarantee a consistent serialVersionUID value across different java compiler implementations, a serializable class must declare an explicit serialVersionUID value. It is also strongly advised that explicit serialVersionUID declarations use the private modifier where possible, since such declarations apply only to the immediately declaring class--serialVersionUID fields are not useful as inherited members." -- Serializable
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

May be this helps.
sonalika kulkarni
Greenhorn

Joined: Dec 10, 2010
Posts: 16
Actually the issue is that in my DB I have blob that refers to class location with some different classpath say "A.b.c.myclass.java" and after the code has been refactored the location for myclass.java has been changed to "d.g.f.myclass.java" so while data fetched from DB tried to find "A.b.c.myclass.java" which is not there now as its new location is "d.g.f.myclass.java" and hence giving me SerializationException. So what is the best way to handle this exception in this case.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

create a dummy package with old definition, read the blob, typecast it, get the class file and finc out the version number.
Use that same for your new package. Try if this works.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: hibernate + An exception occurred: org.hibernate.type.SerializationException