0
親行を挿入しようとしている理由を理解できません。Nhibernate - 子を挿入するときに既存の親行を挿入しようとしている理由
親のマッピング:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="ReportDistribution.Client.ReportMgr.Model.ClientReport, ReportDistribution.Client.ReportMgr.Model"
table="ClientReport"
lazy="false"
dynamic-update="true">
<id name="Id" access="property" column="ReportID">
<generator class="assigned"></generator>
</id>
<property name="MaxAge" access="property" />
<property name="DeleteUnread" access="property" />
<property name="Description" access="property" />
<property name="Name" access="property" />
<bag name="ClientPublications" cascade="all" lazy="false">
<key column="ReportID" />
<one-to-many class="ReportDistribution.Client.ReportMgr.Model.ClientPublication, ReportDistribution.Client.ReportMgr.Model" />
</bag>
</class>
</hibernate-mapping>
子供マッピング:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="ReportDistribution.Client.ReportMgr.Model.ClientPublication, ReportDistribution.Client.ReportMgr.Model"
table="ClientPublication"
lazy="false"
dynamic-update="true">
<id name="Id" access="property" column="PublicationID">
<generator class="assigned"></generator>
</id>
<property name="CreatedOn" access="property" type="DateTime"></property>
<property name="IsMarkedForDeletion" access="property"></property>
<property name="IsDeleted" access="property"></property>
<property name="HasBeenRead" access="property"></property>
<property name="ReceivedOn" access="property" type="DateTime"></property>
<property name="FileExtension" access="property"></property>
<property name="IsDownloaded" access="property"></property>
<property name="MustRead" access="property"></property>
<many-to-one
name="Report"
class="ReportDistribution.Client.ReportMgr.Model.ClientReport, ReportDistribution.Client.ReportMgr.Model"
lazy="false"
column="ReportID">
</many-to-one>
</class>
</hibernate-mapping>
親クラス(レポート)は、子クラスのコレクションである性質を持っています。 子クラス(パブリケーション)には、親オブジェクトであるプロパティがあります。事前に
おかげで....
ClientPublicationsバッグにinverse = trueを入れてみましたか? – Rashack
パブリケーションID列にNULLが挿入されているため、ADOExceptionが発生します。 – empo
残念ですが、最後のコメントはid generatorを "native"に変更しているためです。 – empo