We're updating the issue view to help you get more done. 

Attempt to resolve foreign key metadata from JDBC metadata failed to find column mappings for foreign when keywords auto quoting is enabled

Description

This is a follow-up of the issue 10802. https://hibernate.atlassian.net/browse/HHH-10802

Test case

pom.xml

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <hibernate.version>5.2.2.Final</hibernate.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

application.properties

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #Database configuration spring.datasource.url: jdbc:postgresql://localhost:5432/postgres spring.datasource.driverClassName: org.postgresql.Driver spring.datasource.username: postgres spring.datasource.password: postgres spring.datasource.platform: postgresql spring.datasource.continue-on-error: false spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect spring.jpa.properties.hibernate.format_sql: true spring.jpa.generate-ddl: true spring.jpa.hibernate.ddl-auto: update spring.jpa.properties.hibernate.implicit_naming_strategy: default spring.jpa.hibernate.naming.physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.properties.hibernate.auto_quote_keyword: true spring.jpa.show-sql: false

Entity: Match.java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package com.example.model; import java.io.Serializable; import java.util.Map; import java.util.TreeMap; import javax.persistence.CollectionTable; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; @Entity public class Match implements Serializable { private static final long serialVersionUID = 795832280311186376L; @Id private Long id; @ElementCollection(fetch = FetchType.EAGER) @CollectionTable private Map<Integer, Integer> awayTeamGoalTimeline = new TreeMap<>(); }

Spring boot app entry point - DemoApplication.java

1 2 3 4 5 6 7 8 9 10 11 12 package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }

Steps
1. Start the application so that the schema is created.
2. Start the application once again, it crashes upon starting with

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Attempt to resolve foreign key metadata from JDBC metadata failed to find column mappings for foreign key named [fk38far8ndkwu15myx333actku7] at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl$ForeignKeyBuilderImpl.build(InformationExtractorJdbcDatabaseMetaDataImpl.java:727) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl$ForeignKeyBuilderImpl.build(InformationExtractorJdbcDatabaseMetaDataImpl.java:708) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getForeignKeys(InformationExtractorJdbcDatabaseMetaDataImpl.java:691) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.extract.internal.TableInformationImpl.foreignKeys(TableInformationImpl.java:88) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.extract.internal.TableInformationImpl.getForeignKey(TableInformationImpl.java:99) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.findMatchingForeignKey(SchemaMigratorImpl.java:529) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applyForeignKeys(SchemaMigratorImpl.java:505) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.performMigration(SchemaMigratorImpl.java:314) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:136) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:109) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:307) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:490) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:878) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] ... 21 common frames omitted

From my point of view it has to have something in common with auto quoting key words set to true. I use PostgreSQL database.

In the previous versions the table for this entity was created by the following generated sql.

CREATE TABLE "Match"

Now it is created by
CREATE TABLE public."Match"

Seems like correcting one thing for cross schema mappings causes errors in one schema mappings. :]

Environment

JDK 1.8

Status

Assignee

Andrea Boriero

Reporter

Paweł Jaguś

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.2

Priority

Critical