Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 存储来自非实体父级的字段_Hibernate_Jpa - Fatal编程技术网

Hibernate 存储来自非实体父级的字段

Hibernate 存储来自非实体父级的字段,hibernate,jpa,Hibernate,Jpa,我有一个类,我不希望它存储在数据库中,基本上它是用来从http请求接收这样的信息 class Address { private String address; private String postCode; // + getters and setters } 请记住,此类不是一个实体。 现在我想通过继承创建一个实体 @Entity class StorableAddress extends Address { // id and a few more f

我有一个类,我不希望它存储在数据库中,基本上它是用来从http请求接收这样的信息

class Address {
    private String address;
    private String postCode;

    // + getters and setters

}
请记住,此类不是一个实体。 现在我想通过继承创建一个实体

@Entity
class StorableAddress extends Address {
   // id and a few more fields.
}
当我保存StorableAddress时,它不会保存地址和邮政编码中的任何字段。是否有解决方案,或者我必须复制所有字段?

简短回答-您应该复制值,而不是使用继承

你所描述的是一个例子

为了避免使用DTO时出现样板代码,您可以使用以下工具