views:

1092

answers:

3

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?

+1  A: 

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.

John Ellinwood
Thank you for the input.
Johan Hammar
A: 

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.

javashlook
Thanks for the clarification.
Johan Hammar
+1  A: 

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

ian