4

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?

Rais Alam
  • 6,970
  • 12
  • 53
  • 84
user1448876
  • 49
  • 1
  • 2

2 Answers2

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