Hi,
Thanks for the useful advices. I have couple of questions need to be clarified.
For better understanding my scenario.
I have a parent entity (HrpBbstorzs
https://pastebin.com/TCrVJBGT) which is for employee data and a collection need to be filled up (HrpBbmchi07
https://pastebin.com/4Re7g7Xr) which contains managers belong to particular employee.
Employee can has more than one manager and managers can have multiple employees.
Should I put this relation into HrpBbmchi07 entity ?
@ManyToOne
@JoinFormula(
"(HRP_BBMCHI07.COMPANY = PARENT.COMPANY AND HRP_BBMCHI07.BBM_BBST_TORZSSZAM = PARENT.TORZSSZAM AND VALTDATUM in (select max(VALTDATUM) from HRP_BBMCHI07 F where F.FELETTESTORZSSZAM=FELETTESTORZSSZAM AND F.BBM_BBST_TORZSSZAM=BBM_BBST_TORZSSZAM AND F.COMPANY=COMPANY group by valtdatum))"
)
private Parent parent;
If so and
@OneToMany(mappedBy = "parent")
List<HrpBbmchi07> felettes = new ArrayList<>();
is kept in HrpBbstorzs then the following error occurs.
org.hibernate.AnnotationException: A Foreign key refering hu.bluesystem.hrportal.model.HrpBbstorzs from hu.bluesystem.hrportal.model.HrpBbmchi07 has the wrong number of column. should be 2
This is why HrpBbstorzs has composite key with 2 columns and in other hand HrpBbmchi07 has 3 of them (valtdatum is the third).
TIA,
Sandor