Hibernate throws SQLGrammarException: Error accessing table metadata when @Table is used with schema value and no catalog

Description

If an entity is annotated with @Table and the schema attribute is given a value but the catalog no AND the persistence.xml file does not fill in the hibernate.default_catalog, then this happens:

From my investigations, SQL Server complains because Hibernate issues a query to get table metadata without specifying the database name

Looking in the code, in InformationExtractorJdbcDatabaseMetaDataImpl.java, the problem I think is at line 224:

The code explicitly uses both catalog and schema from the table annotation even though only one might have been specified. (catalog != null

 

schema != null)

Shouldn't it fall back to the current namespace value for the one that is not specified? It doesn't make sense to force the user to specify the database name in persistence.xml or @Table just because the schema was specified. This wasn't required before (worked in 4.3)

Environment

Windows 7, Wildfly 10, Java 8

Status

Assignee

Chris Cranford

Reporter

Andrei Serea

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Blocker
Configure