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:
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:
The 'T' prefix is not removed.
Steps To Reproduce
- Pull https://github.com/gsartori/issue-gorm-hasmany-fieldnames
- ./gradlew bootRun
- 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
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:
Findings
Impact
When domain classes use naming conventions (e.g. T* prefix), schema generation becomes inconsistent:
This forces the use of
static mappingto create correct column names:Actual Behaviour
Join tables are created, but FK columns are derived from the raw entity class names, not the resolved table names:
The 'T' prefix is not removed.
Steps To Reproduce
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