问题描述
我的友谊sql表具有列friend_1, friend_2, status
.我的User
类(下面的代码片段)中具有以下映射.当前user.getInitiatedFriendships
返回Friendships
的列表,其中列friend_1
的值等于我正在调用此getter的用户的ID.user.getInvitedToFriendships()
返回Friendships
,其中列friend_2
等于该用户的ID.
My friendships sql table has column friend_1, friend_2, status
.I have the following mappings in my (snippet below) User
class. Currently user.getInitiatedFriendships
returns list of Friendships
where value of column friend_1
is equal to ID of the user I'm calling this getter on.user.getInvitedToFriendships()
returns Friendships
where column friend_2
is equal to ID of this user.
我想知道是否有可能在此行@OneToMany(mappedBy = "invitingUser" +>some check if status=0<)
中添加一些内容,以便也对列status
进行检查,并且只返回那些Friendships
其中status = 0
吗?
I want to know if it is possible to add something to this line @OneToMany(mappedBy = "invitingUser" +>some check if status=0<)
to also perform a check on column status
and only return those Friendships
where status = 0
?
谢谢
@Entity
@Table(name="users")
public class User {
...
@OneToMany(mappedBy = "invitingUser")
List<Friendship> initiatedFriendships;
@OneToMany(mappedBy = "invitedUser"})
List<Friendship> invitedToFriendships;
....
推荐答案
对不起,我想出了另一种方法来在google中搜索它并找到了它.这就是答案:
Sorry, I came up for another way to search for it in google and found it. This is the answer:
@OneToMany(mappedBy = "invitingUser")
@Where(clause = "status = 0")
List<Friendship> initiatedFriendships;
这篇关于JPA过滤来自映射关联的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!