I have a Spring Data JPA backend using Hibernate as the ORM implementation.
This is the model:
__________ _________________________
|Person | |MailConfig |
|________| |_______________________|
| id PK | | uid PK-FK(Person.uid) |
| uid | | ... |
| ... | | |
|________| |_______________________|
@Entity
@Table(name="Person")
public class PersonEntity{
@Id
private String id;
private String uid;
@OneToOne(mappedBy="id", fetch=FetchType.EAGER)
private MailConfigEntity mailConfigNotes;
...
}
@Entity
@Table(name="MailConfig")
public class MailConfigEntity implements Serializable{
@Id
@OneToOne
@JoinColumn(name="uid", table="Person", referencedColumnName="uid", insertable = false, updatable = false)
private PersonEntity id;
...
}
Person table is joined with MailConfig table through a field that is not Person's primary key. When I load an entity using personDAO.findOne(id)
I can see the join in the query is performed against person.id instead of person.uid (on personent0_.id=mailconfig2_.uid
). Any idea why this isn't working?
Query log:
select
personent0_.id as id8_2_,
personent0_.uid as uid8_2_,
mailconfig2_.uid as uid5_1_
from
Person personent0_
left outer join
mailconfig mailconfig2_
on personent0_.id=mailconfig2_.uid
where
personent0_.id=?
As per the documentation, check if this is a foreign key
Also the JoinColumn should be on the owner side of the relationship