posted 6 years ago
Hi,
I was in a situation where I need to refer parent key id in child table. This is one-to-one relationship.
The child table only get the record when certain situation occurred. So not all records from parent are in child table but whatever the records contain by child are in parent table.
I made the changes in the code, when the child records gets inserted into the table, making sure it has a parent id with it.
I want to refer the records from child table and when I fetch them I also need the parent record associated with it.
I am using JPA and I handled the situation by making the following changes into the POJO classes.
The Parent class:
The Child class:
The code is working fine and I don't have any issue with it but just want to understand the things I am doing are right to define and drive the relation between parent and child.
Or is there any other way/workaround to handle the situation in much better way.
The question I asked because I am new to JPA and want to understand its basics.
Thanks,
Atul