@Table annotation UniqueConstraints require physical name for JoinColumns

Description

When using a custom PhysicalNamingStrategy the `columnNames` require the physical name for JoinColumn (ManyToOne), but the logical name for normal columns. (imo the logical name is expected?)

I have tried to create a runnable example here: https://github.com/hpoul/hibernate-joincolumns-test-case/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java

Models:

Setup

`TestPhysicalNamingStrategy` is a simple PhysicalNamingStrategy which simply appends _PHYSICAL to all names:

Problem

when running with:

The error is:

but with the following code it works:

which is weird, because i'd expect both being _PHYSICAL or both being logical names.

my 2 cents

I have traced the problem back to: Ejb3JoinColumn#buildDefaultColumnName(final PersistentClass referencedEntity, final String logicalReferencedColumn) - this method returns the physical name:

but it is called by Ejb3JoinColumn#linkValueUsingDefaultColumnNaming which stores the result as logical name:

( https://github.com/hibernate/hibernate-orm/blob/5.2/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java#L468-L471 )

which probably makes no real sense? anyway, this makes the InFlightMetadataCollectorImpl -> columnNameBindingByTableMap.get("Test2").logicalToPhysical map look like:

which makes no sense for the JoinColumn..

Environment

Hibernate 5.2.12.Final

Assignee

Unassigned

Reporter

Herbert Poul

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure