Skip to main content

Posts

Showing posts from August 9, 2016

Hibernate Annotations & Serializable Interface

Why Hibernate entities needs to implement serializable interface do we really need it always or for some scenarios.???

As per oracle docs "If an entity instance be passed by value as a detached object, such as through a session bean’s remote business interface, the class must implement the Serializable interface."
So its look like it is required in some scenarios but its not mandatory.So may be we take it as a best practice so it would be compatible to use all scenarios. There could be scenarios where we may have to pass JPA pojo or Entity as a value holder object from one layer to another to avoid use of DTO's (Data Transfer object). Which we use by copy & pass the data to next layers.  Some time we may need to pass them over Http layers as a session object may be from presentation layer to business layer. So its content need to be serializable. So we reached on conclusion that its better is most of cases to implement serializable marker interface.
why we have 2 types…