简体   繁体   中英

How to debug, Hibernate "no such filter configured" problem

I have a Hibernate (5.2.18) project, managed by maven. The project includes a test which involves retrieving a database record using a single filter. This test passes.

I package the maven project and use it as a dependency in a second project. The second project has no Hibernate code, except calls into the first project, and no additional Hibernate-related dependencies.

The very same test fails in this second project with a "no such filter configured" error.

When I debug the code I see that in the first situation, the hibernate session is configured with knowledge of 154 filters in the initial project, and only 147 in the second.

Ideally I would like to hear a solution to this problem. But just as useful would be ideas on how to debug this problem.

I have set log4j.logger.org.hibernate=debug but this produces no logging about the configuration of the session's filters. I am stumped as to how to proceed.

I am pretty sure that I know what is going on. Sometimes just writing the question helps.

In my hibernate project I configure the list of annotated classes programmatically (not via xml file, for example). I forgot to add a new class to this list (the class containing the misbehaving filter).

The test works in the Hibernate project because the source code is available and the Entity annotations, and the filter definitions, can be seen. The filters are defined using the @Filter annotations.

When packaged and included as a dependency, I suspect that the annotations defining the filter are not retained, and so Hibernate cannot see the filter annotations unless it is told that this is an annotated class (even though it can still see the @Entity annotation).

I am not sure that I fully understand why some annotations are visible and others are not, but this is the general scheme of the problem. The solution was to add the new class to the explicit list of annotated classes.

I would be delighted to hear a more detailed explanation from someone with more knowledge than I, but I hope that this will point the way for individuals with similar problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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