43
43
import org .hibernate .metamodel .mapping .SelectableConsumer ;
44
44
import org .hibernate .metamodel .mapping .SelectableMapping ;
45
45
import org .hibernate .metamodel .mapping .TableDetails ;
46
+ import org .hibernate .metamodel .mapping .internal .SqlTypedMappingImpl ;
46
47
import org .hibernate .metamodel .spi .MappingMetamodelImplementor ;
47
48
import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
48
49
import org .hibernate .spi .NavigablePath ;
@@ -451,8 +452,7 @@ protected String generateSubquery(PersistentClass model, Metadata mapping) {
451
452
subquery .append ( "select " );
452
453
for ( Column col : columns ) {
453
454
if ( !table .containsColumn ( col ) ) {
454
- int sqlType = col .getSqlTypeCode ( mapping );
455
- subquery .append ( dialect .getSelectClauseNullString ( sqlType , getFactory ().getTypeConfiguration () ) )
455
+ subquery .append ( getSelectClauseNullString ( col , dialect ) )
456
456
.append (" as " );
457
457
}
458
458
subquery .append ( col .getQuotedName ( dialect ) )
@@ -467,6 +467,20 @@ protected String generateSubquery(PersistentClass model, Metadata mapping) {
467
467
return subquery .append ( ")" ).toString ();
468
468
}
469
469
470
+ private String getSelectClauseNullString (Column col , Dialect dialect ) {
471
+ return dialect .getSelectClauseNullString (
472
+ new SqlTypedMappingImpl (
473
+ col .getTypeName (),
474
+ col .getLength (),
475
+ col .getPrecision (),
476
+ col .getScale (),
477
+ col .getTemporalPrecision (),
478
+ col .getType ()
479
+ ),
480
+ getFactory ().getTypeConfiguration ()
481
+ );
482
+ }
483
+
470
484
protected String generateSubquery (Map <String , EntityNameUse > entityNameUses ) {
471
485
if ( !hasSubclasses () ) {
472
486
return getTableName ();
@@ -533,9 +547,7 @@ protected String generateSubquery(Map<String, EntityNameUse> entityNameUses) {
533
547
if ( selectableMapping == null ) {
534
548
// If there is no selectable mapping for a table name, we render a null expression
535
549
selectableMapping = selectableMappings .values ().iterator ().next ();
536
- final int sqlType = selectableMapping .getJdbcMapping ().getJdbcType ()
537
- .getDdlTypeCode ();
538
- buf .append ( dialect .getSelectClauseNullString ( sqlType , getFactory ().getTypeConfiguration () ) )
550
+ buf .append ( dialect .getSelectClauseNullString ( selectableMapping , getFactory ().getTypeConfiguration () ) )
539
551
.append ( " as " );
540
552
}
541
553
if ( selectableMapping .isFormula () ) {
0 commit comments