[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2586) Hibernate Serializable classes do not declare serialVersionUID
Manuel Dominguez Sarmiento (JIRA)
noreply at atlassian.com
Thu Aug 14 16:08:06 EDT 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2586?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30870 ]
Manuel Dominguez Sarmiento commented on HHH-2586:
-------------------------------------------------
This might be relevant:
http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid
One last fun thing about SerialVersionUIDs - they differ by compiler. The UIDs calculated by JikesCompiler differ from those calculated by javac. Apparently, there's no clear specification for how to calculate the UID implicitly, another argument for declaring your own. -- NelsonMinar
(If I recall correctly, the algorithm for computing SerialVersionUIDs looks like it's specified precisely--except that it's actually specified in terms of things (compiler-added initialization methods) that are not specified similarly precisely. -- DanielBarclay?)
As I recall, it's worse than that - different JVM's (or maybe it's class libraries) can result in incompatible serializations as well. The moral the FreeNet project took away from this observation (Kaffe was their compiler in question) was to abandon serialization for hand-written serialization based on the Data{Input,Output}Stream classes. Not only do you get reliable storage independent of the JVM and compiler, but then you don't have to muck around with the version ID's... and you don't have to worry about "transient" declarations.
> Hibernate Serializable classes do not declare serialVersionUID
> --------------------------------------------------------------
>
> Key: HHH-2586
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2586
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.0 alpha, 3.0 beta 1, 3.0 beta 2, 3.0 beta 3, 3.0 beta 4, 3.0 rc 1, 3.0 final, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1 beta 1, 3.1 beta 2, 3.1 rc 1, 3.1 rc2, 3.1 rc3, 3.1, 3.1.1, 3.1.2, 3.2.0.alpha1, 3.2.0.alpha2, 3.1.3, 3.2.0 cr1, 3.2.0.cr2, 3.2.0.cr3, 3.2.0.cr4, 3.2.0.cr5, 3.2.0.ga, 3.2.1, 3.2.2, 3.2.3
> Environment: Not specific to any database, platform or Hibernate version.
> Reporter: Manuel Dominguez Sarmiento
> Original Estimate: 2 hours
> Remaining Estimate: 2 hours
>
> None of the Serializable classes in Hibernate declare serialVersionUID (see http://www.hibernate.org/hib_docs/v3/api/serialized-form.html#org.hibernate.collection.AbstractPersistentCollection).
> This is recommended practice for ALL classes that implement the Serializable interface (see Joshua Bloch's Effective Java - Item #54). Adding these fields is trivial and takes little effort, but is a great enhancement if you are serializing Hibernate classes.
> For instance, we upgraded from Hibernate 3.2.2 to 3.2.3 in our production servers. We serialize process state (which sometimes includes references to Hibernate-managed entities) every 30 seconds or so and on shutdown, so in the event of failures or re-deployment, the processes can continue where they left off. We had a huge surprise when deserialization failed completely because AbstractPersistentCollection had slightly changed between the 3.2.2 and 3.2.3 releases, and this caused the automatically-generated default serialVersionUID to change, even though the changes in the serialized form are compatible as far as we can tell.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list