简体   繁体   English

如何从Hibernate Search结果中排除将isDeleted数据库字段设置为0的实体?

[英]How to exclude entities that have isDeleted database field set to 0 from Hibernate Search results?

I implemented a searching system for a web app using Hibernate Search and it works well only that I want to exclude the entities that have the database field isDeleted=0. 我使用Hibernate Search为Web应用程序实现了一个搜索系统,并且仅在我要排除具有数据库字段isDeleted = 0的实体时,它才能很好地工作。 I found that this could be achieved using Criteria but in my case , isDeleted is not mapped to an attribute in my entity class. 我发现可以使用Criteria来实现,但就我而言,isDeleted没有映射到我的实体类中的属性。

Is there any way I could achieve this without modifying the entity class? 在不修改实体类的情况下,有什么方法可以实现?

I haven't worked with java for a while, but I remember that there is a possibility to write explicit named query for the matter using annotation NamedQuery on class level. 我已经有一段时间没有使用Java了,但是我记得有可能在类级别使用注释NamedQuery对此事件编写显式的命名查询。 Examples of named queries are here - http://www.mkyong.com/hibernate/hibernate-named-query-examples/ 命名查询的示例在此处-http: //www.mkyong.com/hibernate/hibernate-named-query-examples/

I am not sure if it works without having the deleted flag mapped to attribute though, you would have to try it. 我不确定在没有将已删除标志映射到属性的情况下是否可以工作,您必须尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM