kiwionly wrote:
hi, I had a class like this
Code:
public class User {
private Address address;
//setter and getter..
}
<many-to-one name="address"
column="address_id"
unique="true"
not-null="false" cascade="all"/>
my question is when i call session.save(user), it perform SQL insert to a new row into address table, but not SQL update ? why ?
how can i make it to perform SQL update the row instead of perform SQL insert ?
any idea ?
kiwi
Please post your code, how you save your user. You should retrieve the address exists in database, and set it to user instead of creating the new address.
Code:
Address addr = ... // load from the database
User user = new User();
...
user.setAddress(addr);
session.save(user);