【发布时间】:2017-08-09 12:23:05
【问题描述】:
我在休眠 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
【问题讨论】:
-
能否将我的回复标记为答案?
标签: java hibernate join one-to-one