[hibernate-issues] [Hibernate-JIRA] Commented: (HBX-964) add serialVersionUID to entity classes

Max Rydahl Andersen (JIRA) noreply at atlassian.com
Mon Jul 16 08:11:52 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HBX-964?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_27509 ] 

Max Rydahl Andersen commented on HBX-964:
-----------------------------------------

I think eclipse's warning is bogus and java.io.Serializable is one of my pet-hates and I guess it's time to document this ;)

I disagree with your suggestion for the following reasons:

hbm2java puts "implements Serializable" because of two reasons:
 1) It is extremely common to serialize entities to have them available in other layers
 2) It was always generated that way (e.g. legacy)

So why do I not go and add serialVersionUID to the generated entities ?

A) by implementing Serializable you just indicate that this object should be able to serialize to a stream, nothing more - nothing less!

B) by adding a serialVersionUID you are indicating much more, namely that this class is serializable *across* different versions of it - and note what eclipse generates is as far as I know exactly the same thing that the vm would do anyway, and hence why have that extra line ?

C) serialVersionUID=1 is *wrong* since the same class can change over time and the id won't be the same.

So what are the options:

Either we generate the full serialversionUID based on class signature but that implies B and that is just not true.
Or we remove the implements serializable, but what does that statement do besides making eclipse's bogus warnings light up and making all entities non-serializable by default ?

Feel very free to convince me of why eclipse's warning is correct and we should all add serialVersionUID even though I'm quite sure very few percent of those people adding the versionuid's doesn't actually do that.







> add serialVersionUID to entity classes
> --------------------------------------
>
>                 Key: HBX-964
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-964
>             Project: Hibernate Tools
>          Issue Type: Improvement
>          Components: hbm2java
>    Affects Versions: 3.2beta10
>            Reporter: Dan Allen
>            Priority: Minor
>         Attachments: HBX-964-v1.txt
>
>   Original Estimate: 5 minutes
>  Remaining Estimate: 5 minutes
>
> The serialVersionUID is recommended for classes that implement java.io.Serializable.  The hbm2java task should either set the serialVersionUID to 1L or automatically generate a value. I prefer setting it to 1L because it is easy and it will work, but if you feel motivated, you can look at what Eclipse does to generate this value from the class signature.
> I have included a patch that just sets it to 1L.

-- 
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