Error in classes that implement java.io.Serializable

0

I have some classes that implement java.io.Serializable, when I go to compile, they all present a warning:

  

The serializable class Fat_uc_dataStatementSql does not declare a   static final serialVersionUID field of type long

What can be happening? What is this constant that he asks?

    
asked by anonymous 09.08.2016 / 03:52

2 answers

1
In runtime each serializable class has a version number (serialVersionUID), in the deserialization the object is checked, if the version of the object is not compatible with the version of the object of which requested an InvalidClassException will occur, so when you declare a serializable class it is convenient to declare a serialVersionUID explicitly which must be static, final, and of type long. But if you do not make explicit a default serialVersionUID will be created at runtime so it does not become mandatory although you should consider doing so it's just a warning and not an error, hugs.

    
09.08.2016 / 04:13
1

Actually, this is just a warning. which can even be disabled with @SuppressWarnings ("serial")

import ...
.
.
.
@SuppressWarnings("serial")
public class AplicacaoEntity implements Serializable {  
    private Long id;
    private String descricao;
.
.
.

or adding the line to the class: private static end long serialVersionUID = 1L; as the example below:

import ...
.
.
.
public class AplicacaoEntity implements Serializable {  
    private static final long serialVersionUID = 1L;
    private Long id;
    private String descricao;
.
.
.

Important: If you are building a JSF project, remember that every session-scoped bean is required to implement serializable;

I hope I have helped;

    
09.08.2016 / 04:06