简体   繁体   中英

How can I inherit Hibernate filters with annotations?

I'm trying to set up a Hibernate filter with annotations. I would like to specify it in a base class and make all sub classes use it but whenever I try to enable it, Hibernate fails to find the filter. Is it possible at all to inherit filter annotations?

Since 3.5.0 it's at least possible for @MappedSuperclass. Not sure if that helps you... see: HHH-4332

Are you using the hibernate filter directly, or are you extending the hibernate filter for your own purposes? Annotations aren't inherited by default in Java, although if you were writing the annotation yourself, and I'm assuming hibernate didn't do this on their annotations, you can specify the @Inherited meta-annotation on your annotation to make it inherit. This only works for Type level annotations, though. Also, some people write an annotation manager to simulate full inheritance. You could do something like that, either extend hibernates mechanism or write a preprocessor that adds the annotations where they should have been inherited.

What John Ellinwood wrote is precisely the case. That is why @Filter needs to be specified on all subclasses, at least in Hibernate Annotations 3.4.0-GA.

Furthermore, although that might not be apparent, you will need the same annotation on all mapped collections of that class, if you expect those collections to be susceptible to filtering as well.

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