I encountered a strange bug involving parent-child entity mapping to similar parent child tables. I am using hibernate-core-4.1.6.Final. The child table is as below:
SCREEN_REQUEST_DETAILS
----------------------------
ID NUMBER(38,0), NOT NULL, PRIMARY KEY
SCREEN_REQUEST_ID NUMBER(38,0), NOT NULL, FOREIGN KEY to ID column in SCREEN_REQUEST table
CATEGORY_ID NUMBER(38,0), NULL, FOREIGN KEY to CATEGORY_ID column in PLATE_WELL_CATEGORY table
:
:
:
goes the restIn my java codes, I saved the parent class, ScreenRequest then the child class ScreenRequestDetails using manual flushing. Whenever I try to flush after saving the child class I get the below exception.
Quote:
ORA-02291: integrity constraint (PHARMAPPS.SCREEN_REQ_DET_CAT_FK) violated - parent key not found
Note the above error appears even though the column CATEGORY_ID in the SCREEN_REQUEST_DETAILS table is nullable. If I remove the FK constraint in the database table the problem disappear. I tried to place the following annotation on the getter property in the entity class but in vain.
Code:
@ManyToOne(fetch = FetchType.LAZY, optional=true)
@JoinColumn(name = "CATEGORY_ID", nullable=true)
public PlateWellCategory getPlateWellCategory() {
return this.platewellCategory;
}
Is nullable foreign key column in a child table supported by Hibernate? Many thanks for any advice and tips!
Warmest regards,
Damon