@@ -30,6 +30,8 @@ public class CriteriaLoader : OuterJoinLoader
3030 private readonly string [ ] userAliases ;
3131 private readonly bool [ ] includeInResultRow ;
3232 private readonly int resultRowLength ;
33+ // caching NH-3486
34+ private readonly string [ ] cachedProjectedColumnAliases ;
3335
3436 public CriteriaLoader ( IOuterJoinLoadable persister , ISessionFactoryImplementor factory , CriteriaImpl rootCriteria ,
3537 string rootEntityName , IDictionary < string , IFilter > enabledFilters )
@@ -48,6 +50,11 @@ public CriteriaLoader(IOuterJoinLoadable persister, ISessionFactoryImplementor f
4850 resultTypes = walker . ResultTypes ;
4951 includeInResultRow = walker . IncludeInResultRow ;
5052 resultRowLength = ArrayHelper . CountTrue ( IncludeInResultRow ) ;
53+ // fill caching objects only if there is a projection
54+ if ( translator . HasProjection )
55+ {
56+ cachedProjectedColumnAliases = translator . ProjectedColumnAliases ;
57+ }
5158
5259 PostInstantiate ( ) ;
5360 }
@@ -74,7 +81,7 @@ public IType[] ResultTypes
7481 get { return resultTypes ; }
7582 }
7683
77- protected override string [ ] ResultRowAliases
84+ protected override string [ ] ResultRowAliases
7885 {
7986 get { return userAliases ; }
8087 }
@@ -113,22 +120,20 @@ protected override object[] GetResultRow(object[] row, IDataReader rs, ISessionI
113120
114121 if ( translator . HasProjection )
115122 {
116- IType [ ] types = translator . ProjectedTypes ;
117- result = new object [ types . Length ] ;
118- string [ ] columnAliases = translator . ProjectedColumnAliases ;
119-
123+ result = new object [ ResultTypes . Length ] ;
124+
120125 for ( int i = 0 , position = 0 ; i < result . Length ; i ++ )
121126 {
122- int numColumns = types [ i ] . GetColumnSpan ( session . Factory ) ;
123-
124- if ( numColumns > 1 )
127+ int numColumns = ResultTypes [ i ] . GetColumnSpan ( session . Factory ) ;
128+
129+ if ( numColumns > 1 )
125130 {
126- string [ ] typeColumnAliases = ArrayHelper . Slice ( columnAliases , position , numColumns ) ;
127- result [ i ] = types [ i ] . NullSafeGet ( rs , typeColumnAliases , session , null ) ;
131+ string [ ] typeColumnAliases = ArrayHelper . Slice ( cachedProjectedColumnAliases , position , numColumns ) ;
132+ result [ i ] = ResultTypes [ i ] . NullSafeGet ( rs , typeColumnAliases , session , null ) ;
128133 }
129134 else
130135 {
131- result [ i ] = types [ i ] . NullSafeGet ( rs , columnAliases [ position ] , session , null ) ;
136+ result [ i ] = ResultTypes [ i ] . NullSafeGet ( rs , cachedProjectedColumnAliases [ position ] , session , null ) ;
132137 }
133138 position += numColumns ;
134139 }
@@ -222,4 +227,4 @@ protected override IEnumerable<IParameterSpecification> GetParameterSpecificatio
222227 return translator . CollectedParameterSpecifications ;
223228 }
224229 }
225- }
230+ }
0 commit comments