Extremely wierd problem I am facing. My test setup is very simple: one-to-one association between user and address. Both tables use the uid column as the PK.
[b]Mapping documents:[/b]
<class name="test.User" table="user">
<id name="uid" column="uid" type="long">
<generator class="assigned"/>
</id>
<property name="first_name" column="first_name" type="string"/>
<property name="last_name" column="last_name" type="string"/>
<one-to-one name="address" cascade="all" class="test.Address" outer-join="auto" constrained="false" />
</class>
<class name="test.Address" table="address">
<id name="uid" type="long" column="uid" unsaved-value="null">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<property name="street" column="street" type="string"/>
<one-to-one name="user" class="test.User" outer-join="auto" constrained="true" />
[b]Code between sessionFactory.openSession() and session.close():[/b]
User u = new User();
u.setUid(200);
Address a = new Address();
a.setUid(200);
a.setUser(user);
u.setAddress(a);
There are 2 issues:
1. Hibernate is trying to update the address table instead of inserting. I've tried many things (played around with unsaved-value, etc.) but can't get it to insert.
2. It's using the wrong columns for the update to the address table !! It is using the columns for the user table. Following is what it tries to do:
update address set first_name = ?, last_name = ? where uid = ?
Obviously, the database complains that there is no column called first_name in the address table. I have gone over my mapping files many times to make sure I am not doing something silly but I just can't find what's wrong. As you can see from the above mapping, it is a very simple one-to-one association.
Please help.
|