Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why EJB need to implement serializable interface?

Is there any reason why EJB classes need to be serializable? I've heard it has something to do with the fact that RMI is being used under the hood. I know how RMI (remote method invocation) works, there's a remote object registered on the server side and only the stub of remote object is sent to the client, not the whole object.

So in RMI applications the methods of remote object need to take arguments and return values that are serializable, as they are being sent over the network, but not the remote object itself.

like image 802
user107986 Avatar asked Sep 09 '15 17:09

user107986


People also ask

Why do we need to implement Serializable interface?

Serializable is a marker interface (has no data member and method). It is used to "mark" Java classes so that the objects of these classes may get a certain capability. The Cloneable and Remote are also marker interfaces. The Serializable interface must be implemented by the class whose object needs to be persisted.

What will happen if we don't implement Serializable?

The Student would not be Serializable, and it will act like a normal class. Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link.

What is the main purpose of serialization?

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

What is the use of Serializable interface in spring boot?

Serialization and Deserialization in Spring Boot. In terms of Rest, APIs Serialization is what Spring boot does when it converts the Java object to JSON object, and similarly, Deserialization is when it converts JSON object to Java object.


1 Answers

The reason that the old J2EE style EJBS that implement javax.ejb.EntityBean, javax.ejb.SessionBean and javax.ejb.MessageDrivenBean should be serializable is historical. The original javax.ejb.EnterpriseBean interface that these extend happens to itself extend java.io.Serializable. In the very early EJB days it was thought that this was needed to facilitate moving beans between JVMs.

All practical reasons for EJBs to actually implement Serializable disappeared by the time that the EJB 2.0 specification was published.

The introduction of EJB 3 removed the requirement for any of these interfaces (and subsequently java.io.Serializable) to be implemented.

No EJB specification since EJB 2.0 has specified that EJBs must be serializable. This has only been implicit because of the interface inheritance.

The implicit requirement disappears altogether with EJB 3.x.

like image 174
Steve C Avatar answered Sep 19 '22 22:09

Steve C