From 0cab17ad28d0742cce49e750e55d878fa9290f05 Mon Sep 17 00:00:00 2001 From: mehmetali2003 Date: Sun, 29 Jun 2025 17:01:43 +0300 Subject: [PATCH 1/2] HHH-14270 GroupedSchemaValidatorImpl / NameSpaceTablesInformation does not find different-case table information in case insensitive environment --- .../schema/extract/spi/NameSpaceTablesInformation.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java index f7342ef4a2a7..96d596e5c536 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java @@ -26,7 +26,15 @@ public void addTableInformation(TableInformation tableInformation) { } public TableInformation getTableInformation(Table table) { - return tables.get( identifierHelper.toMetaDataObjectName( table.getQualifiedTableName().getTableName() ) ); + String tableName = identifierHelper.toMetaDataObjectName( table.getQualifiedTableName().getTableName() ); + if ( tables.containsKey( tableName.toLowerCase() )) { + return tables.get( tableName.toLowerCase() ); + } + else if ( tables.containsKey( tableName.toUpperCase() ) ) { + return tables.get( tableName.toUpperCase() ); + } + + return null; } public TableInformation getTableInformation(String tableName) { From 86ec26cede904eff426d0b92f66a67d269cdb32b Mon Sep 17 00:00:00 2001 From: mehmetali2003 Date: Thu, 17 Jul 2025 16:13:25 +0300 Subject: [PATCH 2/2] HHH-14270 HHH-14270 GroupedSchemaValidatorImpl / NameSpaceTablesInformation does not find different-case table information in case insensitive environment --- .../spi/NameSpaceTablesInformation.java | 12 +----- .../spi/NameSpaceTablesInformationTest.java | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformationTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java index 96d596e5c536..f86f02c85e58 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformation.java @@ -22,19 +22,11 @@ public NameSpaceTablesInformation(IdentifierHelper identifierHelper) { } public void addTableInformation(TableInformation tableInformation) { - tables.put( tableInformation.getName().getTableName().getText(), tableInformation ); + tables.put(identifierHelper.toMetaDataObjectName( tableInformation.getName().getTableName()), tableInformation); } public TableInformation getTableInformation(Table table) { - String tableName = identifierHelper.toMetaDataObjectName( table.getQualifiedTableName().getTableName() ); - if ( tables.containsKey( tableName.toLowerCase() )) { - return tables.get( tableName.toLowerCase() ); - } - else if ( tables.containsKey( tableName.toUpperCase() ) ) { - return tables.get( tableName.toUpperCase() ); - } - - return null; + return tables.get( identifierHelper.toMetaDataObjectName( table.getQualifiedTableName().getTableName() ) ); } public TableInformation getTableInformation(String tableName) { diff --git a/hibernate-core/src/test/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformationTest.java b/hibernate-core/src/test/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformationTest.java new file mode 100644 index 000000000000..528e154f224d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/tool/schema/extract/spi/NameSpaceTablesInformationTest.java @@ -0,0 +1,43 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.tool.schema.extract.spi; + +import org.hibernate.boot.model.relational.QualifiedTableName; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.mapping.Table; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.util.ServiceRegistryUtil; +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; +import org.hibernate.tool.schema.extract.internal.TableInformationImpl; +import org.hibernate.boot.model.relational.Namespace.Name; +import org.hibernate.boot.model.naming.Identifier; +import org.mockito.Mockito; + + +public class NameSpaceTablesInformationTest { + + @Test + @JiraKey(value = "HHH-14270") + public void testNameSpaceTablesInformation() { + StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistry(); + JdbcEnvironment jdbcEnvironment = ssr.getService( JdbcEnvironment.class ); + IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper(); + + NameSpaceTablesInformation nameSpaceTablesInformation = new NameSpaceTablesInformation(identifierHelper); + Name schemaName = new Name( new Identifier( "-", false ), new Identifier( "-", false ) ); + InformationExtractor informationExtractor = Mockito.mock( InformationExtractor.class ); + QualifiedTableName tableName = new QualifiedTableName( schemaName, new Identifier( "-", false ) ); + + TableInformation tableInformation = new TableInformationImpl( informationExtractor, identifierHelper, tableName, false, null ); + nameSpaceTablesInformation.addTableInformation( tableInformation ); + final Table table = new Table( "orm", tableName.getTableName().getText() ); + nameSpaceTablesInformation.getTableInformation( table ); + boolean tableMatched = tableInformation.getName().getTableName().getText().equals( tableName.getTableName().getText() ); + Assert.assertTrue("Table matched: ", tableMatched); + } +}