我已经阅读了一些关于 hibernate 和实体序列化的主题,但仍然无法理解为什么我的应用程序可以工作,尽管我没有实现 Serializable。
"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." (c)
我有什么:
使用 Hibernate 的简单 Spring MVC 项目。我有 MyEntity 数据表,以及用户从我的应用程序编辑它的功能。
什么问题:
据我了解,用户在填写表单时将拥有一个 myEntity 对象。因此,myEntity 处于分离状态。 但是,MyEntity 没有实现可序列化
我的问题:
最佳答案
Hibernate 不要求实体为 Serializable
.
"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." (c)
这个语句是一个常见的混淆源,因为它与 Hibernate 无关。实际上,这意味着如果您打算在需要可序列化的上下文中使用您的实体,它们应该是
Serializable
.由于 Spring MVC 不需要模型属性为
Serializable
同样(除非您想利用 session 持久性来使用 @SessionAttributes
存储在 session 中的属性),因此您无需担心您的情况的可序列化性。
关于spring - Hibernate 实体可序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18741445/