开发者

NHibernate + Many-to-Many + bag + mapping table

开发者 https://www.devze.com 2023-03-30 02:27 出处:网络
I have following 3 classes. BusinessStream Scheme Bus_Stream_Scheme_Map When I try to execute transaction.Commit() method, after session.SaveOrUpdate() for BusinessStream, I get following error,

I have following 3 classes.

BusinessStream
Scheme
Bus_Stream_Scheme_Map

When I try to execute transaction.Commit() method, after session.SaveOrUpdate() for BusinessStream, I get following error,

cannot insert NULL into ("DBO"."BUS_STREAM_SCHEME_MAP"."BUS_STREAM_SCHEME_MAP_ID")

HBM Files,

BusienssStream

<class name="BusinessStream" table="BUS_STREAM">
<id name="Id" column="BS_ID" type="Int32" >
  <generator class="sequence">
    <param name="sequence">BUS_STREAM_SEQ</param>
  </generator>
</id>
<property name="Name" column="Name" type="String"/>
<property name="Description" column="Description" type="String"/>
<bag name="Schemes" table="BUS_STREAM_SCHEME_MAP" lazy="false">
  <key column="BUS_STREAM_ID"></key>
  <many-to-many class="Scheme" column="SCHEME_ID"></many-to-many>
</bag>

</class>

Scheme

<class name="Scheme" table="SCHEME_DEF">
    <id name="Id">
     <column name="SCHEME_ID"/>
     <generator class="native">
          <param name="sequence">SCHEME_DEF_SEQ</param>
     </generator>
</id>
    <property name="Description" column="SCHEME_DESC" type="String"/>
</class>

BusinessStream_Scheme_Map

<class name=开发者_如何学运维"BusinessStreamSchemeMapping" table="BUS_STREAM_SCHEME_MAP">
<id name="Id">
  <column name="BUS_STREAM_SCHEME_MAP_ID"/>
  <generator class="native">
    <param name="sequence">BUS_STREAM_SCHEME_MAP_SEQ</param>
  </generator>
</id>
</class>

What am I doing wrong?


This is just a guess, but would it work if you set BUS_STREAM_SCHEME_MAP_ID to be an auto-incrementing field?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号