简体   繁体   中英

hibernate.TransientObjectException:object references an unsaved transient instance-save the transient instance before flushing-after hibernate upgrade

I get the error after upgrading to hibernate 3.6.0.FINAL but it was working with 3.3.2.GA

My problem is similar to https://forum.hibernate.org/viewtopic.php?p=2452617

In that case they have set cascade="all" to solve the problem.

But In my case, I dont want to update the referenced entity. I dont have bi directonal, relation, it is just a many to one. Most of the similar Question posted here, suggest to do a cascade all, but in my case it dont want to cascade.

my mapping

<class name="org.hmil.ams.com.model.MyUserDetails" table="CMUPMST_TB">
        <id name="username" column="UPMST_USER_NAME" type="java.lang.String"
            unsaved-value="0">
            <generator class="assigned" />
        </id>
        <property name="password" column="UPMST_USER_PWD" type="java.lang.String"
            not-null="true" />
        <property name="UPMST_ROLE_ID" type="long" not-null="true" />

        <many-to-one name="UPMST_ROLE" fetch="join" cascade="none"
            insert="false" update="false"         class="org.hmil.ams.setup.model.CodeMst">
            <column name="UPMST_ROLE_ID" />
        </many-to-one>
</class>

I am using Spring BlazeDS/ flex,My objects are detached. Now when I try to save the newly created MyUserDetails Entity, It says there is transient instance of CodeMst, (I am not updating the entity, but may be BlazeDS while it deserializes the newly Created MyUserDetail, it is instantiating the referenced CodeMst Entity, with null values, this may be causing the issue, but same code was working before upgrade ) Any help to solve this is appreciated.

I actually found a solution here: https://hibernate.atlassian.net/browse/HHH-5908

Deployed the patch. I just added the same fix for the TypeHelper.findDirty method (line 287)

OLD: final boolean[][] includeColumns,
NEW: final boolean[] includeProperties, final boolean[][] includeColumns,

And then in AbstractEntityPersister.findDirty (line 3408):

OLD: propertyColumnUpdateable,
NEW: getPropertyUpdateability(), propertyColumnUpdateable,

Update: The hibernate fix that broke this was https://hibernate.atlassian.net/browse/HHH-2350

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM