I have a many-to-one mapping and not null constraint on the column. i am getting the exception column is Null while saving. Can anybody please suggest how do i use cascade and inverse in this scenario?
Asked
Active
Viewed 2,628 times
4
-
Show us your mapping, and the code you use to save, and we'll tell you what's wrong. – JB Nizet Jun 11 '12 at 12:14
2 Answers
2
Instead of @NotNull
, indicate that the association is not optional using @ManyToOne(optional = false)
. The @NotNull
is not specific to Hibernate; it's a generic bean annotation that may be enforced prior to saving the entitites. To be safe, I suggest using @NotNull
primarily for @Column
attributes.

Paulo Merson
- 13,270
- 8
- 79
- 72
1
the entity with the onetomany/collection will by default maintain the association by cascading to the child which inserts first without the backreference and then updates the id. To solve this the onetomany/collection mapping must have the inverse attribute set and the backreference in the child must be set correctly.

Firo
- 30,626
- 4
- 55
- 94