30
30
import org .hibernate .validator .internal .engine .groups .Sequence ;
31
31
import org .hibernate .validator .internal .engine .groups .ValidationOrder ;
32
32
import org .hibernate .validator .internal .engine .groups .ValidationOrderGenerator ;
33
+ import org .hibernate .validator .internal .metadata .BeanMetaDataManager ;
33
34
import org .hibernate .validator .internal .metadata .core .MetaConstraint ;
34
35
import org .hibernate .validator .internal .metadata .descriptor .BeanDescriptorImpl ;
35
36
import org .hibernate .validator .internal .metadata .descriptor .ConstraintDescriptorImpl ;
@@ -138,11 +139,11 @@ public final class BeanMetaDataImpl<T> implements BeanMetaData<T> {
138
139
private final ValidationOrder validationOrder ;
139
140
140
141
/**
141
- * The class hierarchy for this class starting with the class itself going up the inheritance chain. Interfaces
142
+ * The bean metadata hierarchy for this class starting with the class itself going up the inheritance chain. Interfaces
142
143
* are not included.
143
144
*/
144
145
@ Immutable
145
- private final List <Class <? super T >> classHierarchyWithoutInterfaces ;
146
+ private final List <BeanMetaData <? super T >> beanMetadataHierarchyWithoutInterfaces ;
146
147
147
148
/**
148
149
* {code true} if the default group sequence is redefined, either via a group sequence redefinition or a group
@@ -168,12 +169,11 @@ public final class BeanMetaDataImpl<T> implements BeanMetaData<T> {
168
169
* @param defaultGroupSequenceProvider The default group sequence provider if set.
169
170
* @param constraintMetaDataSet All constraint meta data relating to the represented type.
170
171
*/
171
- public BeanMetaDataImpl (Class <T > beanClass ,
172
+ public BeanMetaDataImpl (BeanMetaDataManager beanMetaDataManager , Class <T > beanClass ,
172
173
List <Class <?>> defaultGroupSequence ,
173
174
DefaultGroupSequenceProvider <? super T > defaultGroupSequenceProvider ,
174
175
Set <ConstraintMetaData > constraintMetaDataSet ,
175
176
ValidationOrderGenerator validationOrderGenerator ) {
176
-
177
177
this .validationOrderGenerator = validationOrderGenerator ;
178
178
this .beanClass = beanClass ;
179
179
this .propertyMetaDataMap = newHashMap ();
@@ -219,10 +219,20 @@ else if ( constraintMetaData.getKind() == ElementKind.BEAN ) {
219
219
this .cascadedProperties = CollectionHelper .toImmutableSet ( cascadedProperties );
220
220
this .allMetaConstraints = CollectionHelper .toImmutableSet ( allMetaConstraints );
221
221
222
- this .classHierarchyWithoutInterfaces = CollectionHelper .toImmutableList ( ClassHierarchyHelper .getHierarchy (
222
+ // get the metadata for all other classes in hierarchy:
223
+ List <Class <? super T >> hierarchy = ClassHierarchyHelper .getHierarchy (
223
224
beanClass ,
224
225
Filters .excludeInterfaces ()
225
- ) );
226
+ );
227
+ List <BeanMetaData <? super T >> beanMetadataHierarchy = new ArrayList <>( hierarchy .size () );
228
+ // metadata for a class `beanClass` should go as a first element in the list
229
+ beanMetadataHierarchy .add ( this );
230
+ for ( int index = 1 ; index < hierarchy .size (); index ++ ) {
231
+ beanMetadataHierarchy .add ( beanMetaDataManager .getBeanMetaData ( hierarchy .get ( index ) ) );
232
+ }
233
+
234
+ this .beanMetadataHierarchyWithoutInterfaces = CollectionHelper .toImmutableList ( beanMetadataHierarchy );
235
+
226
236
227
237
DefaultGroupSequenceContext <? super T > defaultGroupContext = getDefaultGroupSequenceData ( beanClass , defaultGroupSequence , defaultGroupSequenceProvider , validationOrderGenerator );
228
238
this .defaultGroupSequenceProvider = defaultGroupContext .defaultGroupSequenceProvider ;
@@ -352,8 +362,8 @@ public boolean isDefaultGroupSequenceRedefined() {
352
362
}
353
363
354
364
@ Override
355
- public List <Class <? super T >> getClassHierarchy () {
356
- return classHierarchyWithoutInterfaces ;
365
+ public List <BeanMetaData <? super T >> getBeanMetadataHierarchy () {
366
+ return beanMetadataHierarchyWithoutInterfaces ;
357
367
}
358
368
359
369
private static BeanDescriptor createBeanDescriptor (Class <?> beanClass , Set <MetaConstraint <?>> allMetaConstraints ,
0 commit comments