Author: alessandrolt
Date: 2011-04-15 18:37:32 -0400 (Fri, 15 Apr 2011)
New Revision: 20935
Modified:
annotations/patches/3_4_0_GA_CP03_JBPAPP-6312/src/main/java/org/hibernate/cfg/AnnotationBinder.java
Log:
JBPAPP-6312: Filters defined in superclass annotated with @MappedSuperclass are not
inherited in subclasses
Modified:
annotations/patches/3_4_0_GA_CP03_JBPAPP-6312/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
annotations/patches/3_4_0_GA_CP03_JBPAPP-6312/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2011-04-15
22:16:40 UTC (rev 20934)
+++
annotations/patches/3_4_0_GA_CP03_JBPAPP-6312/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2011-04-15
22:37:32 UTC (rev 20935)
@@ -398,6 +398,13 @@
//TODO: be more strict with secondarytable allowance (not for ids, not for secondary
table join columns etc)
InheritanceState inheritanceState = inheritanceStatePerClass.get( clazzToProcess );
AnnotatedClassType classType = mappings.getClassType( clazzToProcess );
+
+ if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) ) {
+ bindQueries( clazzToProcess, mappings );
+ bindTypeDefs( clazzToProcess, mappings );
+ bindFilterDefs( clazzToProcess, mappings );
+ }
+
if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) //will be processed
by their subentities
|| AnnotatedClassType.NONE.equals( classType ) //to be ignored
|| AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element
declaration
@@ -555,16 +562,12 @@
entityBinder.setWhere( whereAnn );
entityBinder.setCache( cacheAnn );
entityBinder.setInheritanceState( inheritanceState );
- Filter filterAnn = annotatedClass.getAnnotation( Filter.class );
- if ( filterAnn != null ) {
- entityBinder.addFilter( filterAnn.name(), filterAnn.condition() );
- }
- Filters filtersAnn = annotatedClass.getAnnotation( Filters.class );
- if ( filtersAnn != null ) {
- for (Filter filter : filtersAnn.value()) {
- entityBinder.addFilter( filter.name(), filter.condition() );
- }
- }
+
+ //Filters are not allowed on subclasses
+ if ( !inheritanceState.hasParents) {
+ bindFilters( clazzToProcess, entityBinder, mappings );
+ }
+
entityBinder.bindEntity();
if ( inheritanceState.hasTable() ) {
@@ -925,7 +928,44 @@
return classesToProcess;
}
+
+ /*
+ * Process the filters defined on the given class, as well as all filters defined
+ * on the MappedSuperclass(s) in the inheritance hierarchy
+ */
+ private static void bindFilters(XClass annotatedClass, EntityBinder entityBinder,
+ Mappings mappings) {
+
+ bindFilters( annotatedClass, entityBinder );
+
+ XClass classToProcess = annotatedClass.getSuperclass();
+ while ( classToProcess != null ) {
+ if(mappings instanceof ExtendedMappings){
+ AnnotatedClassType classType = ((ExtendedMappings)mappings).getClassType(
classToProcess );
+ if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) ) {
+ bindFilters( classToProcess, entityBinder );
+ }
+ }
+ classToProcess = classToProcess.getSuperclass();
+ }
+ }
+
+ private static void bindFilters(XAnnotatedElement annotatedElement, EntityBinder
entityBinder) {
+
+ Filters filtersAnn = annotatedElement.getAnnotation( Filters.class );
+ if ( filtersAnn != null ) {
+ for ( Filter filter : filtersAnn.value() ) {
+ entityBinder.addFilter( filter.name(), filter.condition() );
+ }
+ }
+
+ Filter filterAnn = annotatedElement.getAnnotation( Filter.class );
+ if ( filterAnn != null ) {
+ entityBinder.addFilter( filterAnn.name(), filterAnn.condition() );
+ }
+ }
+
private static void bindFilterDefs(XAnnotatedElement annotatedElement, ExtendedMappings
mappings) {
FilterDef defAnn = annotatedElement.getAnnotation( FilterDef.class );
FilterDefs defsAnn = annotatedElement.getAnnotation( FilterDefs.class );
Show replies by date