简体   繁体   English

我们应该在休眠状态下创建Domain Class时实现Serializable接口吗

[英]Should we implement Serializable interface while making Domain Class in hibernate

I am new in hibernate.I tried some basic CRUD operations using hibernate API. 我是hibernate的新手,我使用hibernate API尝试了一些基本的CRUD操作。

I created a class Person 我创建了一个班级人

@Entity
class Person
{
   String name
}

I was able to save this class in Database. 我能够将此类保存在数据库中。 Till now I was thinking that JPA internally makes this class implement Serializable because only serialization can save the state of an object.But I tried this : 直到现在我一直在考虑JPA在内部使该类实现Serializable,因为只有序列化才能保存对象的状态。但是我尝试这样做:

Person p=new Person();
boolean bool=p instanceof Serializable;    
sop(bool);   //false

Then I created another class Human (found this way of implementation on Hibernate doc ) 然后,我创建了另一个类Human(在Hibernate doc上找到了这种实现方式)

@Entity
class Human implements Serializable
{
    String name    
}

Human h=new Human();
boolean bool=h instanceof Serializable    
sop(bool);  //true

Which way we should create our domain classes and how hibernate internally treats these two ways ? 我们应该以哪种方式创建域类,以及休眠如何在内部处理这两种方式?

Please help. 请帮忙。

If your entities are going to be transfered over a network, to be stored in an HTTP session, or even to be stored in a file on your hard disk then they must implement Serializable . 如果您的实体要通过网络传输,存储在HTTP会话中,或者甚至存储在硬盘上的文件中,则它们必须实现Serializable Otherwise Hibernate has nothing to do with Serialization, check more here 否则,Hibernate与序列化无关,请在此处查看更多信息

Do Hibernate table classes need to be Serializable? Hibernate表类需要可序列化吗?

Beans serialization in JSP JSP中的Bean序列化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM