7
7
import org .hibernate .engine .spi .SessionFactoryImplementor ;
8
8
import org .hibernate .query .results .ResultSetMapping ;
9
9
import org .hibernate .query .results .ResultSetMappingImpl ;
10
+ import org .hibernate .sql .ast .spi .SqlSelection ;
11
+ import org .hibernate .sql .ast .tree .select .QueryGroup ;
12
+ import org .hibernate .sql .ast .tree .select .QueryPart ;
10
13
import org .hibernate .sql .ast .tree .select .SelectStatement ;
11
14
import org .hibernate .sql .results .jdbc .spi .JdbcValuesMappingProducer ;
12
15
import org .hibernate .sql .results .jdbc .spi .JdbcValuesMappingProducerProvider ;
16
+ import org .hibernate .type .descriptor .jdbc .NullJdbcType ;
17
+
18
+ import java .util .List ;
13
19
14
20
/**
15
21
* Standard JdbcValuesMappingProducerProvider implementation
@@ -26,10 +32,19 @@ public class JdbcValuesMappingProducerProviderStandard implements JdbcValuesMapp
26
32
public JdbcValuesMappingProducer buildMappingProducer (
27
33
SelectStatement sqlAst ,
28
34
SessionFactoryImplementor sessionFactory ) {
29
- return new JdbcValuesMappingProducerStandard (
30
- sqlAst .getQuerySpec ().getSelectClause ().getSqlSelections (),
31
- sqlAst .getDomainResultDescriptors ()
32
- );
35
+ return new JdbcValuesMappingProducerStandard ( getSelections ( sqlAst ), sqlAst .getDomainResultDescriptors () );
36
+ }
37
+
38
+ private static List <SqlSelection > getSelections (SelectStatement selectStatement ) {
39
+ if ( selectStatement .getQueryPart () instanceof QueryGroup queryGroup ) {
40
+ for ( QueryPart queryPart : queryGroup .getQueryParts () ) {
41
+ if ( !(queryPart .getFirstQuerySpec ().getSelectClause ().getSqlSelections ()
42
+ .get ( 0 ).getExpressionType ().getSingleJdbcMapping ().getJdbcType () instanceof NullJdbcType ) ) {
43
+ return queryPart .getFirstQuerySpec ().getSelectClause ().getSqlSelections ();
44
+ }
45
+ }
46
+ }
47
+ return selectStatement .getQuerySpec ().getSelectClause ().getSqlSelections ();
33
48
}
34
49
35
50
@ Override
0 commit comments