Why is Spring persistent class PO or javabean often serialized?

Source: Internet
Author: User

Whether using Hibernate or MyBatis in conjunction with spring for development or otherwise, persistent classes in the system tend to be serialized, implements Serializable. I'm still curious, why should I do this? Always only know a general, learning hibernate and MyBatis, some of the books have a few words of introduction, some books cited examples or and spring integration with the example also did not realize serialization, sometimes in your project, if not implement Serializable interface, The system may also be normal without errors.

Finally have this time to find out for yourself this reason, turn over the book, look at the webpage, for this problem data is still relatively small, but I also learned some, on the PO to realize the serialization has a deeper understanding, why to achieve the serialization of the reasons summarized as follows:

1. Hibernate when using a component as a composite primary key, the component class must satisfy one condition: Implement the Java.io.serializable interface.

2. When the cache is configured in MyBatis, the persistence layer needs to be serialized. The cache element <cache> has a ReadOnly property, and the ReadOnly property can be set to TRUE or false. Read-only caching will return the same instance for all callers. Therefore, they cannot be modified, which can greatly improve performance. The writable cache will return a copy of the cached object by serialization. This will be slow, but more secure. So the default value is False.

3, persistent storage, save the state of the object in the storage media so that the exact same copy can be recreated later.

4, by the value of marshaling, especially in the distributed system. If the object is marked as Serializable, the object is automatically serialized, transferred from one application domain to another application domain, and then deserialized to produce an exact copy of the object in the second application domain.

Reprint please indicate-java my life (Chen Leixing) Source: http://blog.csdn.net/chenleixing/article/details/43833413

Why is Spring persistent class PO or javabean often serialized?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.