0

休止状態に問題があります。CollaborateableImpl オブジェクト内に Transaction オブジェクトのリストを格納したいと考えています。

したがって、CollaborateableImpl の休止状態の構成ファイルは次のようになります。

<class name="CollaborateableImpl" table="Collaborateable">
<id name="id" type="int" column="id">
    <generator class="increment" />
</id>

<property name="name" column="name" type="string" not-null="true" />
<property name="keywords" column="keywords" type="string"/>

<!--  Transactions -->
<list name="transactions" table="Transaction" lazy="false" cascade="all"  fetch="select">
    <key>
        <column name="Collaborateable_id" />
   </key>
   <index column="idx"/>
   <one-to-many class="TransactionImpl" />

</list>
</class>

私のトランザクション設定ファイル:

<class name="TransactionImpl" table="Transaction">
<id name="id" type="string" column="id">
    <!-- Generator is not needed, since the id is generated with uuid on client -->
</id>

<map name="vectorClock" table="VectorClockEntry" cascade="delete">
    <key column="Transaction_id" />
    <map-key column="User_id" type="int" />
    <element column="value" type="long" />
</map>
</class>

そこで、CollaborateableImpl オブジェクトを作成し、このオブジェクトを session.save(collaborateableImpl) に保存します。すべて正常に動作します。では、transactionImpl オブジェクトを、collaborateImpl オブジェクトの Transaction のリストに追加したいと思います。

TransactionImpl t = new TransactionImpl();
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
            collaborateableImpl.addTransaction(t);
            session.update(c);
        tx.commit();
        session.flush();
        session.close();

残念ながら、例外がスローされます: java.sql.SQLException: Field 'Collaborateable_id' does not have a default value

休止状態が何を言おうとしているのかはわかりますが、この問題を解決する方法がわかりません。助言がありますか?

4

1 に答える 1

0

解決策を見つけました。トランザクション構成ファイルでタグを定義する必要があります。

<many-to-one name="collaborateable" class="CollaborateableImpl" fetch="select">
        <column name="Collaborateable_id" not-null="true" />
</many-to-one>
于 2012-05-15T21:34:04.080 に答える