Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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/windows/15.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
Java 休眠实体';补丁'/部分更新_Java_Hibernate_Jpa_Orm - Fatal编程技术网

Java 休眠实体';补丁'/部分更新

Java 休眠实体';补丁'/部分更新,java,hibernate,jpa,orm,Java,Hibernate,Jpa,Orm,在hibernate中,我想用RESTAPI调用通过PATCH传递的“一半”实体来更新现有实体 因此这里,HalfEntity将是一个pojo,其中包含基于RESTAPI用户可以发送的内容的getter和setter,这将是Entity的子集 有没有一种最快的方法可以在实体的“一半”中为实体指定新值 所以有机会写一大堆这样的 Entity.setValue(HalfEntity.getValue()); Entity.setValue2(HalfEntity.getValue2()); Enti

在hibernate中,我想用RESTAPI调用通过
PATCH
传递的“一半”实体来更新现有实体

因此这里,
HalfEntity
将是一个pojo,其中包含基于RESTAPI用户可以发送的内容的getter和setter,这将是
Entity
的子集

有没有一种最快的方法可以在实体的“一半”中为实体指定新值

所以有机会写一大堆这样的

Entity.setValue(HalfEntity.getValue());
Entity.setValue2(HalfEntity.getValue2());
Entity.setValue3(HalfEntity.getValue3());
Entity.setValue5(HalfEntity.getValue5());
…我想写下:

Entity.patch(HalfEntity);

这可能吗?

您可以这样做:

public void patch(Object halfEntity) throws IllegalArgumentException, IllegalAccessException{
    for(Field f:halfEntity.getClass().getDeclaredFields()){
        f.setAccessible(true);
        f.set(this, f.get(halfEntity));
    }
}

如果持久性解决方案使用字节码增强,那么它就被丢弃了。