如何创建此实体命名查询

How to create this entity named query

我有一个通知 service.Notification 显示给用户取决于他们 permission.Notification 是在三个 table 的帮助下实现的,它们是通知、通知类型(定义通知类型和它属于定义用户的权限)和权限table(id,和权限名称) 下面添加通知和通知类型table。

通知

public class Notifications  {

@Id 
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String title;
private String deatils;
private String link;
@OneToOne(fetch=FetchType.EAGER)
@PrimaryKeyJoinColumn(name="NotificationTypeId",referencedColumnName="Id")
private NotificationTypes notificationTypes;
private Boolean tenantSpecific;
private Boolean userSpecific;
private Long recieverUserId;
private Boolean activeFlag;
private Long tenantId;
@Temporal(TemporalType.TIMESTAMP)
private Date insertedDttm;
private Long insertedBy;
@Temporal(TemporalType.TIMESTAMP)
private Date updatedDttm;
private Long updatedBy;
}

通知类型实体

public class NotificationTypes implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;

private String typeName;
@Temporal(TemporalType.TIMESTAMP)
private Date insertedDttm;
private Long insertedBy;
@Temporal(TemporalType.TIMESTAMP)
private Date updatedDttm;
private Long updatedBy;

@OneToMany(fetch = FetchType.EAGER)
private List<RLPermissions> permissions;

}

在以上两个实体中,我想通过特定权限查找通知列表 这样 Select nt from notification nt where nt.notificationType.permission in(permissionList) 我如何在命名查询中解决这个问题。

尝试使用joins获取Permission的id,然后传入id列表:

Select nt 
from notification n 
   inner join n.notificationType nt
   inner join nt.permissions p 
where p.id in :permissionIds

在交易方式中:

session.createNamedQuery("query", Notifications.class)
            .setParameterList("permissionIds", permissionIds)
            .list();