Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@MohammedAymanKhan
Copy link

@MohammedAymanKhan MohammedAymanKhan commented Dec 28, 2025

Issue

Hibernate incorrectly reports duplicate column mappings when the same column name (e.g. address) is used in different secondary tables of the same entity. This occurs because checkColumnDuplication() only considers the column name and ignores the table name.

Jira: https://hibernate.atlassian.net/browse/HHH-12678

Changes

  • Modified the column duplication check to qualify column names with their table name (tableName.columnName) when building the uniqueness set.
    This ensures that columns with the same name in distinct tables are no longer treated as duplicates.
  • The change preserves existing behavior for columns within the same table while correctly allowing valid cross-table column name reuse.

Test


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Dec 28, 2025

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="hibernate-style" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please back out this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I have removed the IDE configuration file from the PR.

Copy link
Member

@gavinking gavinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I left a minor suggestion.

Comment on lines 197 to 198
String tableName = ( getTable() != null ) ? getTable().getName() : "";
String uniqueKey = tableName.isEmpty() ? col.getName() : tableName + "." + col.getName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String tableName = ( getTable() != null ) ? getTable().getName() : "";
String uniqueKey = tableName.isEmpty() ? col.getName() : tableName + "." + col.getName();
final var primaryTable = getTable();
final String tableName = primaryTable != null ? primaryTable.getName() : "";
final String uniqueKey = tableName.isEmpty() ? col.getName() : tableName + "." + col.getName();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied. Thanks for the suggestion!

@MohammedAymanKhan MohammedAymanKhan force-pushed the HHH-12678-column-duplication-fix branch from bbbed6d to 8971c53 Compare December 28, 2025 11:31
@MohammedAymanKhan
Copy link
Author

Hi @gavinking and Team,
Thanks again for the review and feedback!

The OpenJDK 25 jobs (hsqldb, h2, mysql, postgresql, etc.) are currently failing with "There were failing tests" in :hibernate-core:test

I’ve seen similar test failures on JDK 25 in other recent PRs as well. Since my change is quite small, I’m wondering

  • Are these JDK 25 test failures related to my code changes, or is this a known/project-wide issue with JDK 25 compatibility?

I’m happy to investigate locally if needed, but wanted to check first since my change is minimal.

Thanks!

@gavinking
Copy link
Member

@MohammedAymanKhan The error is:

        Caused by:
        java.lang.NullPointerException: Cannot invoke "String.isEmpty()" because "tableName" is null
            at org.hibernate.mapping.Value.checkColumnDuplication(Value.java:199)
            at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:400)
            at org.hibernate.mapping.Collection.validate(Collection.java:394)
            at org.hibernate.mapping.Set.validate(Set.java:51)
            at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:468)
            at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:265)
            at 

So it's definitely the result of this change.

Comment on lines 205 to 207
catalog = primaryTable.getCatalog() != null ? Identifier.toIdentifier( primaryTable.getCatalog() ) : null;
schema = primaryTable.getSchema() != null ? Identifier.toIdentifier( primaryTable.getSchema() ) : null;
table = primaryTable.getName() != null ? Identifier.toIdentifier( primaryTable.getName() ) : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
catalog = primaryTable.getCatalog() != null ? Identifier.toIdentifier( primaryTable.getCatalog() ) : null;
schema = primaryTable.getSchema() != null ? Identifier.toIdentifier( primaryTable.getSchema() ) : null;
table = primaryTable.getName() != null ? Identifier.toIdentifier( primaryTable.getName() ) : null;
catalog = primaryTable.getCatalogIdentifier();
schema = primaryTable.getSchemaIdentifier();
table = primaryTable.getNameIdentifier();

table = primaryTable.getName() != null ? Identifier.toIdentifier( primaryTable.getName() ) : null;
}

Identifier columnName = Identifier.toIdentifier( col.getName() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Identifier columnName = Identifier.toIdentifier( col.getName() );
Identifier columnName = col.getNameIdentifier( getBuildingContext() );

Comment on lines 212 to 214
final QualifiedColumnName qualified = new QualifiedColumnName( catalog, schema, table, columnName );

if ( !distinctColumns.add( qualified ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final QualifiedColumnName qualified = new QualifiedColumnName( catalog, schema, table, columnName );
if ( !distinctColumns.add( qualified ) ) {
if ( !distinctColumns.add( new QualifiedColumnName( catalog, schema, table, columnName ) ) ) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beikov Thank you for the review! I have updated the code to use the direct identifier getters as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants