我在休眠A和B有2个实体。这里是相关的代码。休眠一对一连接使用主键不工作
@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;
}
我一样在下文提到的链接中提到 one to one mapping using primary key join column
但是同样的,当我做下面的HQL查询,
"from A a left join a.b"
联接采取下述条件
a.id = b.id
虽然我是德公畜是以下条件
a.id = b.aId
请你记住我的答案回答? –