2017-03-29 9 views
1

다음 nhibernate 매핑이 있는데 일대일 매핑으로 다른 엔티티 TimesheetCellTransactionLine의 별도 열에 복합 키 값을 저장하려고합니다. 어떤 아이디어? 다음과 같은 값을 저장하지 않으면 양쪽 외래 키 열에 null이 전달됩니다.nhibernate에서 복합 키를 이용한 다 대일 매핑

<hibernate-mapping 
    xmlns="urn:nhibernate-mapping-2.2" 
    assembly="ManpowerUK.Indigo.Domain" 
    namespace="ManpowerUK.Indigo.Domain.Timesheets"> 
    <class name="CMSTimesheetCell" lazy="false" table="vw_TimesheetCell" mutable="false"> 
     <composite-id > 
      <key-property name="TimesheetCellId"/> 
      <key-property name="TimesheetCellVersion" column="Version"/> 
     </composite-id> 
     <property name="TimesheetId" not-null="true" /> 
     <property name="IsRemoved" /> 
    </class> 
</hibernate-mapping> 


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ManpowerUK.Indigo.Domain" namespace="ManpowerUK.Indigo.Domain"> 
    <class name="TimesheetCellTransactionLine" lazy="false"> 
     <id column="TransactionLineId"/> 
     <many-to-one name="Timesheet" class="ManpowerUK.Indigo.Domain.Timesheets.TimesheetCellWrite" column="TimesheetId" not-null="true" lazy="proxy"/> 
     <many-to-one name="CMSTimesheetCell" class="ManpowerUK.Indigo.Domain.Timesheets.CMSTimesheetCell" not-null="true" lazy="proxy" cascade="none"> 
     <column name="TimesheetCellId"/> 
     <column name="TimesheetCellVersion"/> 
     </many-to-one> 
    </class> 
</hibernate-mapping> 
+0

귀하의'TimesheetCellTransactionLine' 더 큰지도에서 추출 된 것으로 보인다 스 니펫이 잘못 보인다 (클래스 정의 밖의'subclass') 테스트되지 않습니다. [mcve] (/ help/mcve)를 쓸 수 있습니까? –

답변

1

I는 복합 키

<property name="TimesheetCellId" not-null="true" /> 
    <property name="TimesheetCellVersion" not-null="true" /> 

를 추가하는 추가적인 속성 매핑을 추가하여, 내가 인서트 다음의 매핑을 사용 거짓 캐스케이드 아무것도 업데이트되지 가져 오는 동안 해결.

<many-to-one name="CMSTimesheetCell" class="ManpowerUK.Indigo.Domain.Timesheets.CMSTimesheetCell" not-null="true" lazy="proxy" cascade="none" insert="false" update="false"> 
    <column name="TimesheetCellId"/> 
    <column name="TimesheetCellVersion"/> 
    </many-to-one> 

전체 매핑 파일은 다음과 같습니다.

 <?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ManpowerUK.Indigo.Domain" namespace="ManpowerUK.Indigo.Domain"> 
    <class name="TimesheetCellTransactionLine" lazy="false"> 
     <id column="TransactionLineId" /> 
     <property name="TimesheetCellId" not-null="true" /> 
     <property name="TimesheetCellVersion" not-null="true" /> 
      <many-to-one name="CMSTimesheetCell" class="ManpowerUK.Indigo.Domain.Timesheets.CMSTimesheetCell" not-null="true" lazy="proxy" cascade="none" insert="false" update="false"> 
     <column name="TimesheetCellId"/> 
     <column name="TimesheetCellVersion"/> 
     </many-to-one> 
    </class> 
</hibernate-mapping> 
내가 매핑 별 코드가 활용 솔루션이 대답 보완 것
1

: 당신이 제공

mapping.Class<TimesheetCellTransactionLine>(classMapper => 
{ 
     classMapper.ManyToOne(
      line => line.CMSTimesheetCell, 
      columns 
      (
       columnMapper => columnMapper.Name("TimesheetCellId"), 
       columnMapper => columnMapper.Name("TimesheetCellVersion") 
      ) 
    ); 
});