I have @OneToOne relationship between two classes with the following structure:
ClassA is PendingActionJobs:
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Pending_Actions_Detail_Fk")
public PendingActionDetails getActionDetailsFk() {
return actionDetailsFk;
}
public void setActionDetailsFk(PendingActionDetails aActionDetailsFk) {
actionDetailsFk = aActionDetailsFk;
}
ClassB is called PendingActionDetails:
@OneToOne(mappedBy = "actionDetailsFk", fetch = FetchType.LAZY)
public PendingActionJobs getPendingJob() {
return pendingJob;
}
public void setPendingJob(PendingActionJobs aPendingJob) {
pendingJob = aPendingJob;
}
As a result the pending actions job table has an FK to the primary key in the PendingActionsDetail table. The PendingActionJobs table has many repeating Fks which map to some pk in the details table like:
Pk FK to the PendingActionsDetail
2 1
3 1
4 1
5 1
6 1
7 1
The PendingActionsDetail has only one primary key like:
Pk
1
when I call
createQuery("from PendingActionDetails details LEFT JOIN FETCH details.pendingJob")
it retrieves the collection but when I attempt to fetch the data from the other side, namely from the FK table it says
createQuery("from PendingActionJobs jobs LEFT JOIN FETCH jobs.actionDetailsFk")
it says - more than one row with the same identifier found for class PendingActionJobs. The equivalent sql statement should be:
select * from Pending_Actions_Job jobs
left join
Pending_Actions_Details details
on jobs.Pending_Actions_Detail_Fk =
details.Pending_Actions_Details_Primary_Key
But why does hibernate throw the error? All I want to populate each of the PendingActionJobs FK's rows with the data from the PendingActionDetails Pk. Why does it complain? In other words, I cannot fetch data from both sides but I have to use PendingActionsDetails class?
Aucun commentaire:
Enregistrer un commentaire