I have 2 entities in hibernate A and B. Here is the relevant code.
@Entity
public class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;
@OneToOne(mappedBy = "a", cascade = CascadeType.ALL)
private B b;
}
@Entity
public class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;
@Column(name = "a_id")
@GeneratedValue(generator = "gen")
@GenericGenerator(name = "gen", strategy = "foreign", parameters = @Parameter(name = "property", value = "a"))
private Integer aId;
@OneToOne(fetch = FetchType.LAZY, optional = false)
@PrimaryKeyJoinColumn
private A a;
}
I did the same as mentioned in the below mentioned link one to one mapping using primary key join column
However, when I do the following hql query,
"from A a left join a.b"
the join is taken on the following condition
a.id = b.id
although what I desire is the following condition
a.id = b.aId