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