Skip to content

Grails 7 GORM ignores NamingStrategy for hasMany join table column names (prefixed with entity class name) #15736

Description

@gsartori

Expected Behavior

In Grails 7 (GORM 9 / Hibernate 5.6), join table column names generated for hasMany associations do not consistently apply the configured NamingStrategy.

Instead of using the resolved table names, GORM uses the raw domain class names, including prefixes such as T, when generating join table foreign key columns.

Join table and foreign key columns should respect the naming strategy:

  • book_id
  • author_id

Findings

  • classToTableName() is invoked and works for entity tables
  • Join table generation for hasMany associations does not consistently apply NamingStrategy
  • FK column names are derived from domain class names instead of physical table names

Impact

When domain classes use naming conventions (e.g. T* prefix), schema generation becomes inconsistent:

  • entity tables are correctly renamed
  • join table FK columns still contain class prefixes

This forces the use of static mapping to create correct column names:

    static mapping = {
        team joinTable: [name: "book_authors", key: "author_id", column: "book_id"]
    }

Actual Behaviour

Join tables are created, but FK columns are derived from the raw entity class names, not the resolved table names:

  • tbook_id
  • tauthor_id

The 'T' prefix is not removed.

Steps To Reproduce

  1. Pull https://github.com/gsartori/issue-gorm-hasmany-fieldnames
  2. ./gradlew bootRun
  3. Look at the created tables in the database
  • author_books
  • book_authors

Environment Information

Grails 7.x
GORM 9.x
Hibernate 5.6.x
JDK 17+

Example Application

https://github.com/gsartori/issue-gorm-hasmany-fieldnames

Version

7.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions