From 8cecdd3f43796c134688d99b6387d59600e75738 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 30 Aug 2021 17:45:57 +0200 Subject: [PATCH] HHH-14835 : Fix Sybase Connection#getSchema() throws an exception (cherry picked from commit aaba4767fe2842c442104dff0a377a0f63ecffdd) --- .../org/hibernate/dialect/SybaseDialect.java | 23 +++++++++++++++++++ .../AbstractInformationExtractorImpl.java | 6 +++++ 2 files changed, 29 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java index b20284657c..d6e7186b5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java @@ -6,8 +6,14 @@ */ package org.hibernate.dialect; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; import java.sql.Types; +import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy; +import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; +import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder; +import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport; import org.hibernate.type.descriptor.sql.BlobTypeDescriptor; import org.hibernate.type.descriptor.sql.ClobTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; @@ -48,4 +54,21 @@ public class SybaseDialect extends AbstractTransactSQLDialect { public String getCurrentSchemaCommand() { return "select db_name()"; } + + @Override + public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData) + throws SQLException { + if ( dbMetaData == null ) { + builder.setUnquotedCaseStrategy( IdentifierCaseStrategy.MIXED ); + builder.setQuotedCaseStrategy( IdentifierCaseStrategy.MIXED ); + } + + return super.buildIdentifierHelper( builder, dbMetaData ); + } + + @Override + public NameQualifierSupport getNameQualifierSupport() { + return NameQualifierSupport.CATALOG; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java index 6bb723c2c0..bd6dc598ad 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java @@ -407,6 +407,9 @@ public abstract class AbstractInformationExtractorImpl implements InformationExt } private Identifier getCurrentSchema(JdbcEnvironment jdbcEnvironment) { + if ( jdbcEnvironment.getNameQualifierSupport() == NameQualifierSupport.CATALOG ) { + return null; + } if ( currentSchema != null ) { return currentSchema; } @@ -428,6 +431,9 @@ public abstract class AbstractInformationExtractorImpl implements InformationExt } private Identifier getCurrentCatalog(JdbcEnvironment jdbcEnvironment) { + if ( jdbcEnvironment.getNameQualifierSupport() == NameQualifierSupport.SCHEMA ) { + return null; + } if ( currentCatalog != null ) { return currentCatalog; }