Hibernate新手提醒。对于后面提到的sql查询,等效的hibernate查询是什么?
SELECT DISTINCT meetupid
FROM meetups
INNER JOIN friends
ON meetups.participantphonenumber = friends.friendphonenumber
AND friends.userphonenumber = :phoneNumber
我尝试过:
SELECT DISTINCT meetUp.meetUpId
FROM MeetUp meetUp
INNER JOIN Friendship friends
ON meetUp.participantPhoneNumber = friends.friendPhoneNumber
AND friends.userPhoneNumber = :phoneNumber
但这会提供 ERROR: Path expected for join!
。
注意:表格 meetups
和 friends
与任何外键都无关。
TIA
答案 0 :(得分:0)
这不是使用HQL的好例子,因为@AVolpe在他的评论中说。但您应该能够使用子查询在HQL中执行此操作。但实际上......映射或使用SQL。
select m.meetupid from Meetup m
where m.participantPhoneNumber in (
select f.friendPhoneNumber from Friendship f
where f.userPhone = :phoneNumber)