views:

177

answers:

1

I'm talking about a detached object, that later I want to update with saveOrUpdate().

How can we at the same time set null and clear() a referenced collection?

A [1:1] B [1:M] C

B to C reference can be null, that means NO C's records for B.

now I want to be able at the same time set B to null so that all C records were deleted from a database. And then saveOrUpdate A !

Cascading is set to hibernate all, including delete orphan.

I can B.clear(), it will delete all records from C.

I can set B to null, that will set B to null, but C records WILL NOT BE DELETED ! (what a pity! not convenient indeed!)

how then?

Situation is weird, in reality.

I see the workaround in 2 transactions. First trans: clear a collection. Commit transaction.

Now all C records are deleted.

Second transaction: A.setB(null). Commit. That will set a field to NULL.

But how to do it in one step?

+1  A: 

One can use

nullable=true
attribute of Join annotation or a similar thing in xml

EugeneP