Java 休眠:在多对一关系中更新父级

Java 休眠:在多对一关系中更新父级,java,hibernate,Java,Hibernate,在多个关系中更新子项时尝试更新父项。以下是hbm.xml <class name="childProduct" table="CHILD_PRODUCT" lazy="true"> <many-to-one name="parent" class="Parent" column="Parent_ID" lazy="false" update="true"/> </class> 下面是我在Dao类中所做的: //Read the entity entity

在多个关系中更新子项时尝试更新父项。以下是
hbm.xml

<class name="childProduct" table="CHILD_PRODUCT" lazy="true">
  <many-to-one name="parent" class="Parent" column="Parent_ID" lazy="false" update="true"/>
</class>
下面是我在Dao类中所做的:

//Read the entity
entity = dao.read(request.getId());
//Set the entity from request
entity.setSomeAttribute(request.getSomeAttribute());
entity.setParent(request.getParent());
通过这种方式,如果我不发送请求中的任何属性值,它将被设置为null作为Parent。但这种情况不会发生在儿童产品上


如何确保只更新从请求发送的值

您可以使用
注释
,以避免xml映射。不清楚您在问什么,或者您的代码在做什么。儿童产品不会发生什么情况?只有您在实体上设置的值将被更新,您未接触的值将不会被更新。
//Read the entity
entity = dao.read(request.getId());
//Set the entity from request
entity.setSomeAttribute(request.getSomeAttribute());
entity.setParent(request.getParent());