簡體   English   中英

如何在大型項目上修復“對象引用未保存的瞬態實例-在刷新之前保存瞬態實例”?

[英]How can I fix “object references an unsaved transient instance - save the transient instance before flushing” on a large project?

我已經在Ubuntu 14.04和Tomcat 6上下載並安裝了Perseus項目的源代碼( 開放源代碼 )。該項目多年來沒有被修改,因此它必須是休眠中的一些新功能。

我在很多線程上都看到了解決方案,但是它們解決了調試代碼的問題,而不是移植一個肯定可以“一次”運行的項目。 自2008年至2011年以來,我正在使用的代碼沒有經過修改。 (我確定他們現在正在“ Mandriva Linux 2010.2”上運行它。)因此,我需要能夠解決此問題的大規模方法-搜索/替換方法或配置文件更改。 我從未使用過休眠狀態,所以我不理解所發布答案的全部含義。

謝謝。

另外,文件不使用@注釋語法,但是映射似乎是通過XML文件完成的。 此時,如果我知道要更改什么,我將不介意僅更新所有這些文件。

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="perseus.document.dao">
    <class name="HibernateChunkDAO$ChunkRow" table="hib_chunks" batch-size="10">

    <id name="id" type="int" column="id" unsaved-value="null">
        <generator class="native" />
    </id>

    <property name="documentID" column="document_id" type="string"
        length="50" index="doc_idx doc_type_idx doc_type_value_idx
        doc_cid_idx doc_so_eo_idx doc_so_eo_type_idx doc_dq_idx
        doc_so_eo_type_val_idx" />

    <property name="elementName" column="element" type="string"
        length="20" />
    <property name="type" column="type" type="string" length="30"
        index="doc_type_idx doc_type_value_idx doc_so_eo_type_idx
        doc_so_eo_type_val_idx" />
    <property name="value" column="value" type="string" length="250"
        index="doc_type_value_idx doc_so_eo_type_val_idx" />

    <property name="position" column="position" type="int" />
    <property name="absolutePosition" column="abs_position" type="int" />

    <property name="chunkID" column="chunk_id" type="string"
        length="255" index="doc_cid_idx" />

    <property name="openTags" column="open_tags" type="text" />
    <property name="closeTags" column="close_tags" type="text" />

    <property name="startOffset" column="start_offset" type="int"
        index="doc_so_eo_idx doc_so_eo_type_idx doc_so_eo_type_val_idx" />
    <property name="endOffset" column="end_offset" type="int"
        index="doc_so_eo_idx doc_so_eo_type_idx doc_so_eo_type_val_idx" />

    <property name="displayQuery" column="display_query" type="string"
        length="100" index="doc_dq_idx" />
    <property name="head" column="head" type="text" />
    <property name="headLanguage" column="head_lang" type="string"
        length="10" />
    <property name="hasCustomHead" column="custom_head" type="boolean" />

        <set name="frequencies" inverse="true" cascade="all-delete-orphan"
            lazy="true" batch-size="30">
            <key column="chunk_id" on-delete="cascade" />
            <one-to-many class="perseus.ie.freq.Frequency" />
        </set>

        <many-to-one name="lemma" column="lemma_id" cascade="all" lazy="false" />

        <!--
        <list name="senses" inverse="false" cascade="all-delete-orphan"
            lazy="false" batch-size="30">
            <key column="chunk_id" />
            <list-index column="position" />
            <one-to-many class="perseus.voting.Sense" />
        </list>
-->
    </class>
</hibernate-mapping>

發生這種情況是由於以下原因:

您已經在實體中定義了一個尚未持久化的關聯,並且在持久化該關聯之前,您嘗試刷新Session。例如,您有一個具有臨時實例集合的collection關聯,因此您必須持久化此collection首先在沖洗之前。

要解決此問題,您有2個選擇:

  1. 通過調用Session.save()方法,將集合手動保存在代碼中。

  2. 如果要在Hibernate XML文件中使用標簽或要使用注釋,請在您的集合關聯上使用cascade =“ all”(對於xml)或cascade = CascadeType.ALL(對於注釋)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM