问题在标题中。下面我只是描述了我的一些想法和发现。
当我有一个非常简单的域模型(3 个没有任何关系的表)时,我所有的实体都没有实现 Serializable
接口(interface)。
但是当域模型变得更复杂时,我得到了一个 RuntimeException
,说我的一个实体没有实现 Serializable
。
我使用 Hibernate 作为 JPA 实现,我想知道:
- 这是特定于供应商的要求/行为吗?
- 我的可序列化实体会发生什么情况?它们是否应该可序列化以进行存储或传输?
- 什么时候需要使我的实体可序列化?
最佳答案
根据 JPA 规范:
If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.
“JSR 220:Enterprise JavaBeansTM,版本 3.0 Java Persistence API 版本 3.0,最终版本 2006 年 5 月 2 日”
关于java - JPA 实体何时以及为什么应该实现 Serializable 接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2020904/