I am reposting this because I failed to receive any usefull answer.
A have a bidirectional one-to-one mapping with a foreign key.
<class table="person">
<one-to-one name="car" lazy="false" cascade="all"/>
....
</class>
<class table="car" lazy="false">
<many-to-one not-null="true" insert="false" unique="true"
column="person_id"
update="false" name="person"/>
....
</class>
Person p = new Person();
Car c = new Car();
p.setCar(c);
session.saveOrUpdate(person);
By here everything is Ok and all the id's are automatically set by hibernate.
The problem comes when I am trying to flush it to the database.
session.flush();
There is an exception that I can not put a null value for the person_id in Car. Shouldn't hibernate take care of this. Works well for many-to-one mapping. Maybe the problem is that there are no update and insert tags for one-to-one (I am setting from the other side of the foreign key)
Maybe some of you have had a similar problem, Thanks Zarko
I solved the problem by deleting cascade="all" on the one-to-one end of the mapping. But,
Back to square one. I need cascade="all" so that the changes can take place on the referenced table.
Anyone has the same problem?
p.s. I must use one-to-one with the foreign key, not with the primary
Zarko
|