From 55ce254d2d8a6652e4f7146060ba270e96916489 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 11 May 2016 20:06:51 +0100 Subject: [PATCH] HHH-10718 - Fix Underscore in table name can result in SchemaExtractionException: More than one table found --- ...tionExtractorJdbcDatabaseMetaDataImpl.java | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java index c818382add..3a57f1e90a 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java @@ -361,33 +361,39 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information Identifier tableName, ResultSet resultSet) throws SQLException { try { - if ( !resultSet.next() ) { + boolean found = false; + TableInformation tableInformation = null; + while ( resultSet.next() ) { + if ( tableName.equals( identifierHelper().toIdentifier( resultSet.getString( "TABLE_NAME" ) ) ) ) { + if ( found ) { + log.multipleTablesFound( tableName.render() ); + final String catalogName = catalog == null ? "" : catalog.render(); + final String schemaName = schema == null ? "" : schema.render(); + throw new SchemaExtractionException( + String.format( + Locale.ENGLISH, + "More than one table found in namespace (%s, %s) : %s", + catalogName, + schemaName, + tableName.render() + ) + ); + } + else { + found = true; + tableInformation = extractTableInformation( + catalog, + schema, + tableName, + resultSet + ); + + } + } + } + if ( !found ) { log.tableNotFound( tableName.render() ); - return null; } - - final TableInformation tableInformation = extractTableInformation( - catalog, - schema, - tableName, - resultSet - ); - - if ( resultSet.next() ) { - log.multipleTablesFound( tableName.render() ); - final String catalogName = catalog == null ? "" : catalog.render(); - final String schemaName = schema == null ? "" : schema.render(); - throw new SchemaExtractionException( - String.format( - Locale.ENGLISH, - "More than one table found in namespace (%s, %s) : %s", - catalogName, - schemaName, - tableName.render() - ) - ); - } - return tableInformation; } finally {