这是我在 SQL 查询字符串中所期望的:
SELECT dbo.FRIEND.FriendId, dbo.FRIEND.MemberId, dbo.FRIEND.FriendMemberId, dbo.FRIEND.DateAdded
FROM dbo.FRIEND INNER JOIN
dbo.MEMBER ON dbo.FRIEND.FriendMemberId = dbo.MEMBER.MemberId
WHERE (dbo.MEMBER.Activate = 1)
这是我有关系的实体:实体朋友字段
@Id
@Column(name = "[FriendId]")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long friendId;
@Column(name = "[MemberId]")
private Long memberId;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "[FriendMemberId]")
private Member friendMember;
@Column(name = "[DateAdded]")
private Date dateAdded;
实体成员字段
@Id
@Column(name = "[MemberId]")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long memberId;
@Column(name = "[Activate]", columnDefinition = "boolean default true")
private boolean activate;
这是我的 HQL 查询:
FROM Friend as f Left join f.Member as m WHERE f.MemberId = :memberId AND m.activate = true
但我得到了错误。那么我应该如何编写 HQL 查询获取数据及其条件取决于 member.activate ?