Confusion over one-to-one mapping in NHibernate

强颜欢笑 提交于 2019-12-23 18:50:38

问题


Can someone suggest to me the appropriate Mapping to be used in the following situation:

Parent Table - AllTransactions

Child Table - TranCategory1, TranCategory2 and TranCategory3 and 8 more.

All twelve tables share the same composite keys. Now count in AllTransactions is the sum of transactions in all the child tables. The child tables contain only unique values from the parent table.

The mapping that I am using is shown below.

I am using constrained="true" in the Parent table only to avoid forming joins in the Select statement for the Parent table. But I guess I am going against the definition of the word 'constrained' which specifies that for every transaction in AllTransactions there must be a transaction in TranCategory1. But actually the reverse is true in my design. So how do I modify my mappings to replicate the correct behavior and also avoid using of joins?

Update: My current mapping is throwing me errors while Joining the Parent and Child table.lease help me modify the mappings so that I can perform a join on the above tables.

Complete Mappings

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>

The Join Query resulting in Error

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

The Exception Message is:

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

The SQL statement shown in the exception message

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

Well I can kind of confirm that this message only comes when I add the mapping for the DisclosureGroupChanges in the AccountEvent table. First I avoided this mapping as I was getting the error. But now I need to perform a Join between these tables and as per my knowledge we can do joins only for related tables in NHibernate. Please correct me if I am wrong here.


回答1:


I got the mistake that I was making.

One of the mappings in the Child Table had the value as "LAST_MODIFIED_DATE=". This was causing me the error always.



来源:https://stackoverflow.com/questions/5569551/confusion-over-one-to-one-mapping-in-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!