How to search in related entity (Hibernate search)

≯℡__Kan透↙ 提交于 2019-12-05 20:54:34

Ok I found the answer myself I changed the annotation sides @IndexEmbedded to other class and @ContainedIn as well so now my fields are

@IndexedEmbedded
    private RecordFolderArrival recordFolderArrival;

And

  @ContainedIn
    private List<RecordFolderAnalysis> recordFolderAnalysis=new ArrayList<>();

Problem solved because @IndexedEmbedded is the property you can navigate to in your queries; I posted the answer cause it might be helpful for others.

I know about the advantages of QueryBuilders, e.g. type safety. But personally, I still find them horrible, as you have to write lots of stuff for simple queries which results in a code not easy to understand.

So, I would prefer to use a JPQL in your case, which looks pretty much like SQL, but handles objects and their attributes and relations. Make it a NamedQuery on your Entity and use parameters for the variable values (instead of String concatenation) and you should be able to solve your query much easier.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!