-1
我使用Hibernate,我想用Hibernate過濾器選項過濾實體。但過濾器將被忽略。工作區實體包括一個用戶實體。而且我希望只有doesent這個用戶的所有工作空間實體在數據庫的電子郵件字段中有一個NULL值。 我期待您的迴音。由於休眠過濾器不起作用
工作區
@Entity
@Table(name = "WORKSPACEENTITY", schema = "pwdmanager")
@PrimaryKeyJoinColumn(name = "workspace_id", referencedColumnName = "id")
@Setter
@Getter
@FilterDef(name = "FILTER")
public class DBWorkspaceEntity{
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "wkse_space")
private List<DBPasswordEntity> pwde_password;
@OneToOne(fetch = FetchType.EAGER)
@Filters({
@Filter(name="FILTER", condition="{u}.usre_email is not null", aliases={@SqlFragmentAlias(alias="u", entity=DBUserEntity.class)}),
})
private DBUserEntity usre_user;
}
用戶
@Entity
@Table(name = "USERENTITY", schema = "pwdmanager")
@Setter
@Getter
@PrimaryKeyJoinColumn(name = "user_id", referencedColumnName = "id")
public class DBUserEntity{
@Basic
@Column(name = "USRE_EMAIL", nullable = true, length = 1024)
private String usre_email;
}
休眠
public class MasterDao{
private Session session;
private Transaction transaction;
private SessionFactory sessionFactory;
public void prepare() {
sessionFactory = HibernateUtil.getSessionFactory();
this.session = sessionFactory.openSession();
}
public void filter(final DBUserEntity usr) {
try {
session.enableFilter("FILTER");
Query query = session.createQuery("FROM " + DBWorkspaceEntity.class.getSimpleName());
List<DBWorkspaceEntity> result = query.list();
session.disableFilter("FILTER_USER");
} catch (final HibernateException ex) {
log.error(ex);
}
}
}
我將過濾條件更改爲USRE_EMAIL IS NOT NULL,並且得到相同的結果 – Dominik