Image

Imagekrasbutch wrote in Imagejava_dev

hibernate and cascade operations

Hi colleagues! Could you please help?

Intro. DB schema contains object A which related with object B like "one-to-many". It means that the copy of the object A may has many related copies of the object B. The object B keeps the Id of the related object A in the field with "NOT NULL" attribute.

Problem. Hibernate does following strange things when I'm trying to delete object A:
1) Trys to set "NULL" into field of object B, which keeps an Id of the related object A (sic!);
2) Deletes related objects B;
3) Deletes object A.

So, the 1 point becomes breakpoint, because of MS SQL doesn't lets Hibernate set NULL to the field with "NOT NULL" attribute. I have checked my suggestions -- all 3 points works if I remove restriction "NOT NULL".

Question. Maybe someone knows how to solve this problem?

p.s. Excuse my English :o)

Update. The solve was found thanks to Imagecharles! The parameter inverse="true" must be added to the bag of the object A.