There are 2 Oracle table
Parent (parent_id, name, desc)
Child (id, child_id references Parent(parent_id), created_dt)
child_id is foreign key referencing parent_id in Parent table.
Since the two tables have different name for primary foreign column, the OnetoOne Mapping is created as below :
Parent.java
String name;
String desc;
String parent_id;
@OneToOne(cascade= {CascadeType.ALL}, fetch = FetchType.EAGER, optional = true)
@JoinColumn(name="parent_id", referenceColumnName="child_id", nullable= true, insertable=false, uptadable= false)
private Child child;
//getters & setters
Child.java
String id;
String child_id;
Timestamp createdDt;
//getters & setters
When I try to save using JPA into Parent(ParentRepositary.save) and groovy test cases, I am getting below error:
Referential integrity constraint violation : PARENT FOREIGN KEY(PARENT_ID) REFERENCES CHILD(CHILD_ID).
But in database child_id(foreign key) is referencing to parent_id(primary key). The same ParentRepositary.save is working fine with junit.
Is there anything specific to Mapping relationship that is declared wrong that groovy test case is failing.
Test:
Parent p = new Parent();
p.setParent_id("P123");
p.setName("name");
p.setDesc("desc");
parentRepositary.save(p);
parentRepositary is extending JpaRepositary.