Skip to content

Commit 62dd443

Browse files
committed
HHH-19559 don't overwrite the default schema/catalog set in properties
1 parent d858586 commit 62dd443

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

hibernate-core/src/main/java/org/hibernate/relational/internal/SchemaManagerImpl.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,22 @@ public SchemaManager forSchemaAndCatalog(String schemaName, String catalogName)
5555
return new SchemaManagerImpl( sessionFactory, metadata, schemaName, catalogName );
5656
}
5757

58+
private void addSchemaAndCatalog(Map<String, Object> properties) {
59+
if ( schemaName != null ) {
60+
properties.put( AvailableSettings.DEFAULT_SCHEMA, schemaName );
61+
}
62+
if ( catalogName != null ) {
63+
properties.put( AvailableSettings.DEFAULT_CATALOG, catalogName );
64+
}
65+
}
66+
5867
@Override
5968
public void exportMappedObjects(boolean createSchemas) {
6069
Map<String, Object> properties = new HashMap<>( sessionFactory.getProperties() );
6170
properties.put( AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.CREATE_ONLY );
6271
properties.put( AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_ACTION, Action.NONE );
6372
properties.put( AvailableSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS, createSchemas );
64-
properties.put( AvailableSettings.DEFAULT_SCHEMA, schemaName );
65-
properties.put( AvailableSettings.DEFAULT_CATALOG, catalogName );
73+
addSchemaAndCatalog( properties );
6674
SchemaManagementToolCoordinator.process(
6775
metadata,
6876
sessionFactory.getServiceRegistry(),
@@ -77,8 +85,7 @@ public void dropMappedObjects(boolean dropSchemas) {
7785
properties.put( AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.DROP );
7886
properties.put( AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_ACTION, Action.NONE );
7987
properties.put( AvailableSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS, dropSchemas );
80-
properties.put( AvailableSettings.DEFAULT_SCHEMA, schemaName );
81-
properties.put( AvailableSettings.DEFAULT_CATALOG, catalogName );
88+
addSchemaAndCatalog( properties );
8289
SchemaManagementToolCoordinator.process(
8390
metadata,
8491
sessionFactory.getServiceRegistry(),
@@ -93,8 +100,7 @@ public void validateMappedObjects() {
93100
properties.put( AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.VALIDATE );
94101
properties.put( AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_ACTION, Action.NONE );
95102
properties.put( AvailableSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS, false );
96-
properties.put( AvailableSettings.DEFAULT_SCHEMA, schemaName );
97-
properties.put( AvailableSettings.DEFAULT_CATALOG, catalogName );
103+
addSchemaAndCatalog( properties );
98104
SchemaManagementToolCoordinator.process(
99105
metadata,
100106
sessionFactory.getServiceRegistry(),
@@ -108,8 +114,7 @@ public void truncateMappedObjects() {
108114
Map<String, Object> properties = new HashMap<>( sessionFactory.getProperties() );
109115
properties.put( AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.TRUNCATE );
110116
properties.put( AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_ACTION, Action.NONE );
111-
properties.put( AvailableSettings.DEFAULT_SCHEMA, schemaName );
112-
properties.put( AvailableSettings.DEFAULT_CATALOG, catalogName );
117+
addSchemaAndCatalog( properties );
113118
SchemaManagementToolCoordinator.process(
114119
metadata,
115120
sessionFactory.getServiceRegistry(),
@@ -123,8 +128,7 @@ public void populate() {
123128
Map<String, Object> properties = new HashMap<>( sessionFactory.getProperties() );
124129
properties.put( AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.POPULATE );
125130
properties.put( AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_ACTION, Action.NONE );
126-
properties.put( AvailableSettings.DEFAULT_SCHEMA, schemaName );
127-
properties.put( AvailableSettings.DEFAULT_CATALOG, catalogName );
131+
addSchemaAndCatalog( properties );
128132
SchemaManagementToolCoordinator.process(
129133
metadata,
130134
sessionFactory.getServiceRegistry(),

0 commit comments

Comments
 (0)