一個一對一的映射可有人建議我適當的映射在下列情況下使用:混淆了NHibernate的
父表 - AllTransactions
子表 - TranCategory1,TranCategory2和TranCategory3和另有8個。
所有十二個表共享相同的組合鍵。現在計算在於所有子表中的交易總和。子表只包含來自父表的唯一值。
我正在使用的映射如下所示。
我在Parent表中使用constrained =「true」只是爲了避免在Parent表的Select語句中形成連接。但是我想我反對'constrained'這個詞的定義,它指定了對於每個在transactionsnsactions中的事務,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>
連接查詢資源ulting在錯誤
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中的相關表進行連接。如果我在這裏錯了,請糾正我。
我認爲你沒有在你的問題中明確表格之間的關係。每個桌子擁有什麼樣的物品?他們的關係的基數是什麼? – 2011-04-06 17:53:26