Why should POJO classes implement the Serializable interface?

Why should Java POJO classes implement an interface Serializable? What happens if I do not implement Serializable?

@Entity
@Table(name="Customer")
public class Customer implements Serializable {

    private static final long serialVersionUID = -5294188737237640015L;
    /**
     * Holds Customer id of the customer
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "cust_id")
    private int Custid;

    /** Holds first Name of the customer*/
    @Column(name = "first_name")
    private String firstName;

    /** Holds last Name of the customer */
    @Column(name = "last_name")
    private String lastName;

    /** Holds Customer mobile number of customer*/
    @Column(name = "cust_mobile")
    private long MobileNo;

    /**Holds customer address of customer*/
    @Column(name = "cust_address")
+4
source share
2 answers

At first, this is no longer an ordinary Old Java object, because it has annotations.

But being in your premise, Serializable is required in POJOs if they are intended for use on distributed systems and systems that use file caching and cleaning and reading.

Basically, JPA implementations are implemented in a distributed manner and use caching, so this ALWAYS is necessary for a Serializable implementation.

Read the discussion for more information.

+6

POJO EJB.

POJO , - .

, EJB .

JEE5 EJB.

, . .

BTW: , "JavaBeans".

0

Source: https://habr.com/ru/post/1542452/


All Articles