Java 休眠实体';补丁'/部分更新
在hibernate中,我想用RESTAPI调用通过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
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));
}
}
如果持久性解决方案使用字节码增强,那么它就被丢弃了。