We're updating the issue view to help you get more done. 

Null foreign key results in Transient Object Exception

Description

Two tables A and B where B is parent table and the relation between A and B is unidirectional many-to-one.

mapping for A:

<hibernate-mapping package="parms">
<class name="A" table="A" lazy="true" batch-size="20" select-before-update='true' >
<id name="id" column="ID">
<generator class="increment"/>
</id>
<many-to-one name="b" column="Ba_ID" class="B" not-found="ignore" cascade="none" lazy="false" not-null="false" unique="false" />
<property name="place" column="PLACE"/>
</class>

mapping for B:

<class name="B" table="B" lazy="true" batch-size="10" select-before-update="true">
<cache usage="read-write"/>
<id name="id" column="B_ID" >
<generator class="assigned"/>
</id>
<property name="programId" column="GROUP_ID" unique="true"/>
</class>

Also some of rows of table A have null values for column Ba_ID.
Now retrieval of these rows which have null values for column Ba_ID works fine. And it retrieves a null relationship between the tables for these rows. Now when I try to update column PLACE. It tries to update column Ba_ID also and there it throws a TransientOBjectException.
But nothing is being changed for that column. Also cascade is set to "none".

Transaction scope code

A a=_form.getA(id);
a.setPlace("place");
sess.saveOrUpdate(a);
tx.commit();
sess.close();

And the last SQL statement being tried to be executed is:
UPDATE A set ......(all columns )..... where ID =?

And the exception thrown is:

[ERROR] AbstractFlushingEventListener - -Could not synchronize database state with session <org.hibernate.TransientObjectException: B>
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)

Environment

Hibernate version 3.2 cr3, Oracle 8i

Status

Assignee

Unassigned

Reporter

maxtor

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Blocker