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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With