gpt4 book ai didi

java - 如何避免在 hibernate 中更新父对象时更新子对象?

转载 作者:太空宇宙 更新时间:2023-11-04 08:07:47 26 4
gpt4 key购买 nike

我不知道是我的设计本身有问题还是什么。但任何人都可以给我一个解决方案吗?我有一个对象,PlanningItem。由此,我需要使用 PlanningItem 的两个属性从另一个表获取记录。所以我创建了 View ,并将该 View 添加为 PlanningItem 中的一对多关系记录。当我更新规划项目时,我收到错误。在这里,我准备将 View 更改为子选择或其他任何内容。请提出继续的想法。

下面是我的代码。

ViewPlannigItem.hbm.xml

<class
name="com.cotyww.ipmasterdata.core.entity.master.ViewPlannigItem"
table="VW_PLANNING_ITEM" >
<id name="planningIrc" type="string" column="PLANNING_IRC">
<generator class="assigned" />
</id>

<property name="planningIRCDesc" column="PLANNING_ITEM_DESC"
type="string" />


<property name="programId" column="PROGRAM_ID" type="string" />


<property name="salesOrgId" column="SALES_ORG_ID"
type="integer" />

<property name="salesBrandId" column="SALES_BRAND_PKEY"
type="integer" />

<many-to-one name="salesBrand" update="false" insert="false"
class="com.cotyww.ipmasterdata.core.entity.master.SalesBrand"
column="SALES_BRAND_PKEY" />

<many-to-one name="salesOrg" update="false" insert="false"
class="com.cotyww.ipmasterdata.core.entity.master.SalesOrg"
column="SALES_ORG_ID" />

</class>

PlanningItem.hbm.xml

<class 
name="com.cotyww.ipmasterdata.core.entity.master.PlanningItem"
table="Planning_Item">
<id name="planningIrc" type="string" column="PLANNING_IRC">
<generator class="assigned" />
</id>

<property name="programId" column="Program_Id" type="string" />

<property name="planningitemDesc" column="Planning_Item_Desc"
type="string" />

<many-to-one name="hierarchyCode" update="false" insert="false"
class="com.cotyww.ipmasterdata.core.entity.master.GmmBrand"
column="Gmm_Hierarchy_Code" />

<property name="gmmhierarchyCode" column="Gmm_Hierarchy_Code"
type="string" />

<many-to-one name="gmmcategoryCode" update="false"
insert="false"
class="com.cotyww.ipmasterdata.core.entity.master.GmmCategory"
column="Category_Code" />
<property name="categoryCode" column="Category_Code"
type="string" />

<set name="lstViewPlanningItem" cascade="none" >
<key column="PLANNING_IRC" />
<one-to-many not-found="ignore"
class="com.cotyww.ipmasterdata.core.entity.master.ViewPlannigItem" />
<filter name="planningsalesORg"
condition="SALES_ORG_ID = :salesOrgId" />
</set>

<property name="modifiedBy" column="Audit_User" type="string" />
<property name="modifiedDate" column="Audit_Date" type="date" />
<property name="createdBy" column="Created_By" type="string" />
<property name="createdDate" column="Created_Date" type="date" />

</class>
<sql-query name="nextPlanningItemSequenceValueC1US">
<![CDATA[ SELECT SQ_PLANNING_ITEM_PKEY_C1US.nextVal FROM dual ]]>
</sql-query>

<sql-query name="nextPlanningItemSequenceValueC1CA">
<![CDATA[ SELECT SQ_PLANNING_ITEM_PKEY_C1CA.nextVal FROM dual ]]>
</sql-query>

<sql-query name="nextPlanningItemSequenceValueL1US">
<![CDATA[ SELECT SQ_PLANNING_ITEM_PKEY_L1US.nextVal FROM dual ]]>
</sql-query>

<sql-query name="nextPlanningItemSequenceValueL1CA">
<![CDATA[ SELECT SQ_PLANNING_ITEM_PKEY_L1CA.nextVal FROM dual ]]>
</sql-query>

<sql-query name="nextPlanningItemSequenceValueP1US">
<![CDATA[ SELECT SQ_PLANNING_ITEM_PKEY_P1US.nextVal FROM dual ]]>
</sql-query>

<sql-query name="nextPlanningItemSequenceValueP1CA">
<![CDATA[ SELECT SQ_PLANNING_ITEM_PKEY_P1CA.nextVal FROM dual ]]>
</sql-query>
<filter-def name="planningsalesORg">
<filter-param name="salesOrgId" type="integer" />
</filter-def>

数据库 View

CREATE OR REPLACE FORCE VIEW COREMASTER.VW_PLANNING_ITEM
(PLANNING_IRC, PLANNING_ITEM_DESC, PROGRAM_ID, SALES_ORG_ID, SALES_BRAND_PKEY,
GMM_HIERARCHY_CODE)
AS
SELECT P.PLANNING_IRC,
P.PLANNING_ITEM_DESC,
P.PROGRAM_ID,
nvl(MAP.SALES_ORG_ID,MAP1.SALES_ORG_ID) as sales_org,
nvl(MAP.SALES_BRAND_PKEY,MAP1.SALES_BRAND_PKEY) as sales_brand_pkey,
P.GMM_HIERARCHY_CODE
FROM PLANNING_ITEM P,
GMM_MAP MAP,
GMM_MAP MAP1
WHERE
P.GMM_HIERARCHY_CODE = MAP.GMM_HIERARCHY_CODE(+)
AND P.CATEGORY_CODE = Map.GMM_CATEGORY_CODE(+)
AND P.GMM_HIERARCHY_CODE = MAP1.GMM_HIERARCHY_CODE(+)
AND Map1.GMM_CATEGORY_CODE IS NULL;

最佳答案

尝试在关系参数的一对多方面设置 inverse="true"。这将告诉 hiberante 在更新父级时不要更新关系(FK 列)。

我的意思是下一步:

<set name="lstViewPlanningItem"  cascade="none"  inverse="true">
<key column="PLANNING_IRC" />
<one-to-many not-found="ignore"
class="com.cotyww.ipmasterdata.core.entity.master.ViewPlannigItem" />
<filter name="planningsalesORg"
condition="SALES_ORG_ID = :salesOrgId" />
</set>

关于java - 如何避免在 hibernate 中更新父对象时更新子对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11791981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com