@@ -20,10 +20,8 @@ public abstract class SubqueryExpression : AbstractCriterion
20
20
private QueryParameters parameters ;
21
21
private IType [ ] types ;
22
22
23
- [ NonSerialized ] private CriteriaQueryTranslator innerQuery ;
24
-
25
23
protected SubqueryExpression ( String op , String quantifier , DetachedCriteria dc )
26
- : this ( op , quantifier , dc , true )
24
+ : this ( op , quantifier , dc , true )
27
25
{
28
26
}
29
27
@@ -44,16 +42,23 @@ public IType[] GetTypes()
44
42
45
43
public override SqlString ToSqlString ( ICriteria criteria , ICriteriaQuery criteriaQuery , IDictionary < string , IFilter > enabledFilters )
46
44
{
47
- InitializeInnerQueryAndParameters ( criteriaQuery ) ;
45
+ ISessionFactoryImplementor factory = criteriaQuery . Factory ;
46
+
47
+ var innerQuery = new CriteriaQueryTranslator (
48
+ factory ,
49
+ criteriaImpl , //implicit polymorphism not supported (would need a union)
50
+ criteriaImpl . EntityOrClassName ,
51
+ criteriaQuery . GenerateSQLAlias ( ) ,
52
+ criteriaQuery ) ;
53
+
54
+ types = innerQuery . HasProjection ? innerQuery . ProjectedTypes : null ;
48
55
49
56
if ( innerQuery . HasProjection == false )
50
57
{
51
58
throw new QueryException ( "Cannot use subqueries on a criteria without a projection." ) ;
52
59
}
53
60
54
- ISessionFactoryImplementor factory = criteriaQuery . Factory ;
55
-
56
- IOuterJoinLoadable persister = ( IOuterJoinLoadable ) factory . GetEntityPersister ( criteriaImpl . EntityOrClassName ) ;
61
+ IOuterJoinLoadable persister = ( IOuterJoinLoadable ) factory . GetEntityPersister ( criteriaImpl . EntityOrClassName ) ;
57
62
58
63
//patch to generate joins on subqueries
59
64
//stolen from CriteriaLoader
@@ -73,11 +78,6 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteri
73
78
sql = factory . Dialect . GetLimitString ( sql , offset , limit , offsetParameter , limitParameter ) ;
74
79
}
75
80
76
- // during CriteriaImpl.Clone we are doing a shallow copy of each criterion.
77
- // this is not a problem for common criterion but not for SubqueryExpression because here we are holding the state of inner CriteriaTraslator (ICriteriaQuery).
78
- // After execution (ToSqlString) we have to clean the internal state because the next execution may be performed in a different tree reusing the same istance of SubqueryExpression.
79
- innerQuery = null ;
80
-
81
81
SqlStringBuilder buf = new SqlStringBuilder ( ) . Add ( ToLeftSqlString ( criteria , criteriaQuery ) ) ;
82
82
if ( op != null )
83
83
{
@@ -88,7 +88,7 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteri
88
88
{
89
89
buf . Add ( quantifier ) . Add ( " " ) ;
90
90
}
91
-
91
+
92
92
buf . Add ( "(" ) . Add ( sql ) . Add ( ")" ) ;
93
93
94
94
if ( quantifier != null && prefixOp == false )
@@ -101,9 +101,9 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteri
101
101
102
102
public override string ToString ( )
103
103
{
104
- if ( prefixOp )
104
+ if ( prefixOp )
105
105
return string . Format ( "{0} {1} ({2})" , op , quantifier , criteriaImpl ) ;
106
-
106
+
107
107
return string . Format ( "{0} ({1}) {2}" , op , criteriaImpl , quantifier ) ;
108
108
}
109
109
@@ -117,23 +117,6 @@ public override IProjection[] GetProjections()
117
117
return null ;
118
118
}
119
119
120
- public void InitializeInnerQueryAndParameters ( ICriteriaQuery criteriaQuery )
121
- {
122
- if ( innerQuery == null )
123
- {
124
- ISessionFactoryImplementor factory = criteriaQuery . Factory ;
125
-
126
- innerQuery = new CriteriaQueryTranslator (
127
- factory ,
128
- criteriaImpl , //implicit polymorphism not supported (would need a union)
129
- criteriaImpl . EntityOrClassName ,
130
- criteriaQuery . GenerateSQLAlias ( ) ,
131
- criteriaQuery ) ;
132
-
133
- types = innerQuery . HasProjection ? innerQuery . ProjectedTypes : null ;
134
- }
135
- }
136
-
137
120
public ICriteria Criteria
138
121
{
139
122
// NH-1146
0 commit comments