3

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

父表 - 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 关键字\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 中的相关表进行连接。如果我在这里错了,请纠正我。

4

1 回答 1

1

我得到了我正在犯的错误。

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

于 2011-04-07T05:33:35.670 回答