gpt4 book ai didi

c# - 对 NHibernate 中一对一映射的困惑

转载 作者:行者123 更新时间:2023-11-30 18:05:29 25 4
gpt4 key购买 nike

有人可以向我建议在以下情况下使用适当的映射:

父表 - AllTransactions

子表 - TranCategory1、TranCategory2 和 TranCategory3 以及另外 8 个。

所有十二个表共享相同的组合键。现在 AllTransactions 中的计数是所有子表中事务的总和。子表仅包含父表中的唯一值。

我正在使用的映射如下所示。

我在父表中使用 constrained="true"只是为了避免在父表的 Select 语句中形成连接。但我想我违反了“约束”一词的定义,该定义指定对于 AllTransactions 中的每个事务,TranCategory1 中必须有一个事务。但实际上我的设计恰恰相反。那么我该如何修改我的映射以复制正确的行为并避免使用连接呢?

更新:我当前的映射在连接父表和子表时出错。请帮助我修改映射,以便我可以对上述表执行连接。

完成映射

Parent Table Mapping

<composite-id name="Key" class="AccountEventKey">
<key-property name="TransactionId" column="TRANSACTION_ID" type="long"/>
<key-property name="PartitionMonthNum" column="PARTITION_MONTH_NUM" type ="int"/>
</composite-id>

<many-to-one name="RefAuditQueue" class="RefAuditQueue">
<column name="AUDIT_QUEUE_ID" not-null ="true"/>
</many-to-one>

<many-to-one name="RefAuditRule" class="RefAuditRules">
<column name="AUDIT_RULE_ID" not-null ="false"/>
</many-to-one>

<many-to-one name="AccountDailyInfo" class="AccountDailyInfo">
<column name="ACCOUNT_ID" length="19" not-null ="false"/>
<column name="ACCOUNT_INFO_PROCESSING_DATE" not-null="false"/>
</many-to-one>

<one-to-one name="DisclosureGroupChange" class="DisclosureGroupChanges" constrained="true"/>

<bag name="AuditReviewAssignmentList" table="AUDIT_REVIEW_ASSIGNMENT" generic="true" inverse="true" cascade="save-update" lazy="true" >
<key>
<column name="TRANSACTION_ID" sql-type="long" not-null ="true"/>
<column name="PARTITION_MONTH_NUM" sql-type="int" not-null ="true"/>
</key>
<one-to-many class="AuditReviewAssignment"/>
</bag>

<property name="RacfId" type="string" not-null="false">
<column name="RACFID" length="7"/>
</property>

<property name="EmployeeDailyAssignmentKey" type="long" not-null="false">
<column name="EMP_DAILY_ASSIGNMENT_KEY"/>
</property>

<property name="AuditReviewRequiredInd" type="YesNo" not-null="false">
<column name="AUDIT_REVIEW_REQUIRED_IND"/>
</property>

<property name="TransactionAmount" type="long" not-null="false">
<column name="TRANSACTION_AMOUNT"/>
</property>

<property name="TransactionDate" type="Timestamp" not-null="false">
<column name="TRANSACTION_DATE"/>
</property>

<property name="LastModifiedDate" type="Date" not-null="false">
<column name="LAST_MODIFIED_DATE"/>
</property>

<property name="FirstAddedDate" type="Date" not-null="false">
<column name="FIRST_ADDED_DATE"/>
</property>

<property name="AccountReferenceNum" type="string" not-null="false">
<column name="ACCOUNT_REFERENCE_NUM" length="50"/>
</property>

<property name="CcaEtlRunNum" type="long" not-null="true">
<column name="CCA_ETL_RUN_NUM"/>
</property>

1 Child Table Mapping (There are 10 more child tables)

<composite-id name="Key" class="AccountEventKey">
<key-property name="TransactionId" column="TRANSACTION_ID" type="long"/>
<key-property name="PartitionMonthNum" column="PARTITION_MONTH_NUM" type ="int"/>
</composite-id>

<many-to-one name="AccountEvent" class="AccountEvent" insert="false" update="false" unique="true">
<column name="TRANSACTION_ID"/>
<column name="PARTITION_MONTH_NUM"/>
</many-to-one>

<property name="FrDisclosureGrpName" type="string" not-null="false">
<column name="FR_DISCLOSURE_GRP_NAME" length="8"/>
</property>

<property name="ToDisclosureGrpName" type="string" not-null="false">
<column name="TO_DISCLOSURE_GRP_NAME" length="8"/>
</property>

<property name="LastModifiedDate" type="Date" not-null="false">
<column name="LAST_MODIFIED_DATE=" />
</property>

<property name="FirstAddedDate" type="Date" not-null="false">
<column name="FIRST_ADDED_DATE" />
</property>

<property name="CcaEtlRunNum" type="long" not-null="true">
<column name="CCA_ETL_RUN_NUM" />
</property>

导致错误的连接查询

var query1 = _ses.CreateCriteria<AccountEvent>().CreateAlias("DisclosureGroupChange", "discGrp", NHibernate.SqlCommand.JoinType.InnerJoin).List<AccountEvent>()

异常信息是:

"ORA-00923: FROM keyword not found where expected\n"

异常信息中显示的SQL语句

SELECT this_.TRANSACTION_ID as TRANSACT1_15_1_, this_.PARTITION_MONTH_NUM as PARTITION2_15_1_, this_.AUDIT_QUEUE_ID as AUDIT3_15_1_, this_.AUDIT_RULE_ID as AUDIT4_15_1_, this_.ACCOUNT_ID as ACCOUNT5_15_1_, this_.ACCOUNT_INFO_PROCESSING_DATE as ACCOUNT6_15_1_, this_.RACFID as RACFID15_1_, this_.EMP_DAILY_ASSIGNMENT_KEY as EMP8_15_1_, this_.AUDIT_REVIEW_REQUIRED_IND as AUDIT9_15_1_, this_.TRANSACTION_AMOUNT as TRANSAC10_15_1_, this_.TRANSACTION_DATE as TRANSAC11_15_1_, this_.LAST_MODIFIED_DATE as LAST12_15_1_, this_.FIRST_ADDED_DATE as FIRST13_15_1_, this_.ACCOUNT_REFERENCE_NUM as ACCOUNT14_15_1_, this_.CCA_ETL_RUN_NUM as CCA15_15_1_, discgrp1_.TRANSACTION_ID as TRANSACT1_52_0_, discgrp1_.PARTITION_MONTH_NUM as PARTITION2_52_0_, discgrp1_.FR_DISCLOSURE_GRP_NAME as FR3_52_0_, discgrp1_.TO_DISCLOSURE_GRP_NAME as TO4_52_0_, discgrp1_.LAST_MODIFIED_DATE= as LAST5_52_0_, discgrp1_.FIRST_ADDED_DATE as FIRST6_52_0_, discgrp1_.CCA_ETL_RUN_NUM as CCA7_52_0_ FROM CCAPRD1O_AT.ACCOUNT_EVENT this_ inner join CCAPRD1O_AT.DISCLOSURE_GROUP_CHANGES discgrp1_ on this_.TRANSACTION_ID=discgrp1_.TRANSACTION_ID and this_.PARTITION_MONTH_NUM=discgrp1_.PARTITION_MONTH_NUM

好吧,我可以确认只有当我在 AccountEvent 表中添加 DisclosureGroupChanges 的映射时才会出现此消息。首先,我在遇到错误时避免了此映射。但现在我需要在这些表之间执行连接,据我所知,我们只能对 NHibernate 中的相关表进行连接。如果我在这里错了,请纠正我。

最佳答案

我弄错了。

子表中的一个映射的值为“LAST_MODIFIED_DATE=”。这总是导致我出错。

关于c# - 对 NHibernate 中一对一映射的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5569551/

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