I have 2 tables, INQUIRY and ELEMENT with a one-to-many relationship, so the query has many Elements.
I would like to apply the Oracle NOT NULL constraint to the foreign key column ELEMENT.ENQUIRY_ID, as this works best. I have the following collection in the Request object:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "ENQUIRY_ID", referencedColumnName = "ID")
private Set<Element> elements = new HashSet<Element>();
When I apply the NOT NULL constraint, I get the following stack:
Called: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("ELEMENT". "ENQUIRY_ID")
Thus, Hibernate obviously saves the collection of elements before the parent query, and then returns and performs an UPDATE in the foreign key field.
Is there a way to enforce the NOT NULL constraint in the collection foreign key field?
source
share