我使用Hibernate,我希望使用Hibernate过滤器选项过滤实体。但过滤器将被忽略。 Workspace实体包括用户实体。并且我希望只有具有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);
}
}
}
答案 0 :(得分:0)
我认为,过滤条件下的usre_email应该是列名。
USRE_EMAIL