26
26
import org .hibernate .annotations .NotFoundAction ;
27
27
import org .hibernate .annotations .common .reflection .XClass ;
28
28
import org .hibernate .annotations .common .reflection .XProperty ;
29
+ import org .hibernate .boot .model .relational .SqlStringGenerationContext ;
30
+ import org .hibernate .boot .model .relational .internal .SqlStringGenerationContextImpl ;
29
31
import org .hibernate .boot .spi .BootstrapContext ;
30
32
import org .hibernate .boot .spi .MetadataBuildingContext ;
31
33
import org .hibernate .cfg .AccessType ;
32
34
import org .hibernate .cfg .AnnotatedClassType ;
33
35
import org .hibernate .cfg .AnnotationBinder ;
36
+ import org .hibernate .cfg .AvailableSettings ;
34
37
import org .hibernate .cfg .BinderHelper ;
35
38
import org .hibernate .cfg .CollectionPropertyHolder ;
36
39
import org .hibernate .cfg .CollectionSecondPass ;
42
45
import org .hibernate .cfg .PropertyPreloadedData ;
43
46
import org .hibernate .cfg .SecondPass ;
44
47
import org .hibernate .dialect .HSQLDialect ;
48
+ import org .hibernate .engine .config .spi .ConfigurationService ;
49
+ import org .hibernate .engine .jdbc .spi .JdbcServices ;
45
50
import org .hibernate .internal .util .StringHelper ;
46
51
import org .hibernate .mapping .Collection ;
47
52
import org .hibernate .mapping .Column ;
57
62
import org .hibernate .mapping .SimpleValue ;
58
63
import org .hibernate .mapping .ToOne ;
59
64
import org .hibernate .mapping .Value ;
65
+ import org .hibernate .service .ServiceRegistry ;
60
66
import org .hibernate .sql .Template ;
61
67
62
68
/**
@@ -412,6 +418,14 @@ protected Value createFormulatedValue(
412
418
MetadataBuildingContext buildingContext ) {
413
419
Value element = collection .getElement ();
414
420
String fromAndWhere = null ;
421
+ final ServiceRegistry serviceRegistry = buildingContext .getBootstrapContext ().getServiceRegistry ();
422
+ final ConfigurationService configurationService = serviceRegistry .getService ( ConfigurationService .class );
423
+ final SqlStringGenerationContext generationContext = SqlStringGenerationContextImpl .fromExplicit (
424
+ serviceRegistry .getService ( JdbcServices .class ).getJdbcEnvironment (),
425
+ buildingContext .getMetadataCollector ().getDatabase (),
426
+ configurationService .getSetting (AvailableSettings .DEFAULT_CATALOG , String .class , null ),
427
+ configurationService .getSetting ( AvailableSettings .DEFAULT_SCHEMA , String .class , null )
428
+ );
415
429
if ( !( element instanceof OneToMany ) ) {
416
430
String referencedPropertyName = null ;
417
431
if ( element instanceof ToOne ) {
@@ -435,7 +449,7 @@ else if ( element instanceof DependantValue ) {
435
449
referencedEntityColumns = referencedProperty .getColumnIterator ();
436
450
}
437
451
fromAndWhere = getFromAndWhereFormula (
438
- associatedClass .getTable ().getQualifiedTableName (). toString ( ),
452
+ generationContext . format ( associatedClass .getTable ().getQualifiedTableName ()),
439
453
element .getColumnIterator (),
440
454
referencedEntityColumns
441
455
);
@@ -444,9 +458,7 @@ else if ( element instanceof DependantValue ) {
444
458
// HHH-11005 - only if we are OneToMany and location of map key property is at a different level, need to add a select
445
459
if ( !associatedClass .equals ( targetPropertyPersistentClass ) ) {
446
460
fromAndWhere = getFromAndWhereFormula (
447
- targetPropertyPersistentClass .getTable ()
448
- .getQualifiedTableName ()
449
- .toString (),
461
+ generationContext .format (targetPropertyPersistentClass .getTable ().getQualifiedTableName ()),
450
462
element .getColumnIterator (),
451
463
associatedClass .getIdentifier ().getColumnIterator ()
452
464
);
0 commit comments