-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Optimestic lock throws TransientObjectException
PostPosted: Fri Jun 28, 2013 9:04 am 
Newbie

Joined: Sat Apr 27, 2013 4:56 am
Posts: 2
Hi,

I have recently added optimestic lock in my application. After that, when i execute the following code
Code:
            ProjectDoc projectDoc = new ProjectDoc();
            ProjectDocId docId = new ProjectDocId();
            DocCollection docCollection = new DocCollection();
            docCollection.setId(docColId);
            docId.setDocCollection(docCollection);
            docId.setProject(new Project(projId));
            projectDoc.setId(docId);
            session.saveOrUpdate(projectDoc);

it throws Exception.
Code:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:


HBM details
Code:
<hibernate-mapping>
    <class name="ProjectDoc" table="PROJECT_DOC" >
        <composite-id name="id" class="ProjectDocId">
            <key-many-to-one name="docCollection" class="DocCollection">
                <column name="ID" />
            </key-many-to-one>
            <key-many-to-one name="project" class="Project">
                <column name="ID" />
            </key-many-to-one>
        </composite-id>
        <many-to-one name="project" class="Project" update="false" insert="false" fetch="select">
            <column name="ID" not-null="true" />
        </many-to-one>
        <many-to-one name="docCollection" class="DocCollection" update="false" insert="false" fetch="select">
            <column name="ID" not-null="true" />
        </many-to-one>
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="DocCollection" table="DOC_COLLECTION" >
        <id name="id" type="java.lang.Integer">
            <column name="ID" />
            <generator class="native" />
        </id>
        <version name="version" column="VERSION" insert="false" ></version>
        <property name="name" type="java.lang.String">
            <column name="NAME" length="256" not-null="true" />
        </property>
     </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="Project" table="PROJECT" >
    <cache usage="nonstrict-read-write"/>
        <id name="id" type="java.lang.Integer">
            <column name="ID" />
            <generator class="identity" />
        </id>
          <version name="version" column="VERSION" insert="false" ></version>
        <property name="name" type="java.lang.String">
            <column name="NAME" length="256" not-null="true" />
        </property>
      </class>
</hibernate-mapping>


To fix this i had to hit DB(to get Project & DocCollection) and then update hbm.

Is there any other way to fix this problem(ie: without get a record from DB)?
Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.