有人可以向我建议在以下情况下使用适当的映射:
父表 - 发票
子表 - TranCategory1,TranCategory2和TranCategory3以及另外8个。
所有十二个表共享相同的复合键。现在,countnsactions中的count是所有子表中事务的总和。子表仅包含父表中的唯一值。
我正在使用的映射如下所示。
我在Parent表中使用constrained =“true”只是为了避免在Parent表的Select语句中形成连接。但是我想我反对“约束”这个词的定义,它指出对于Timesnsactions中的每个事务,TranCategory1中必须有一个事务。但实际上在我的设计中反过来也是如此。 那么如何修改我的映射以复制正确的行为并避免使用连接?
更新:我当前的映射在加入Parent和Child表时会给我带来错误。请帮我修改映射,以便我可以在上面的表上执行连接。
完成映射
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的映射时才会出现此消息。首先,我避免了这种映射,因为我收到了错误。但是现在我需要在这些表之间执行Join,根据我的知识,我们只能为NHibernate中的相关表进行连接。如果我在这里错了,请纠正我。
答案 0 :(得分:1)
我弄错了。
子表中的一个映射的值为“LAST_MODIFIED_DATE =”。这总是导致我的错误。