Hibernate version: 2.1.6
---
I would like to introduce an simple problem: I have two POJOs:
public class A {
private long Code_A;
private B Test;
... gets and sets ...
}
public class B {
public long Code_B;
... gets and sets ...
}
And I want to map A using <many-to-one> of B :
<many-to-one name="Test" class="B"/>
---
Okey, then imagine the situation where the database field "Test" of the table "A" is NOT UNIQUE and CAN BE NULL. So, the A's dont really NEED an B in Test, and 10000 A's can point to the same B. In SQL we can simple use an "on delete set null" constraint.
Well. In Hibernate, if I do:
A A1 = new A();
B B1 = new B();
A1.setTest(B1);
"session".store(B1);
"session".store(A1);
"session".delete(B1);
It returns an "constraint violation error" because the A1 is using B1. But, I want to delete(B1) and set "Test" on A1 as null.
How do I do that??? How do I map that???
---> Thanx for your patience!!! :) Bernardo S. A. Silva
|