Is there any way to change the default column naming strategy for a referenced entity then the default (name of the class). The docs say to call the method setForeignKeyNaming(ForeignKeyNaming.IGNORE_RENAMING)
on RelationalMappingContext
's NamingStrategy. However, this method is only available on the implementation DefaultNamingStrategy
and JdbcMappingContext
's naming strategy but it is package private (CachingNamingStrategy). Is there a way around this?
Asked
Active
Viewed 38 times
1

Jens Schauder
- 77,657
- 34
- 181
- 348
-
@JensSchauder sorry I didn’t know you could do that – Jul 08 '23 at 08:10
-
1Don't worry and welcome to SO. – Jens Schauder Jul 08 '23 at 08:28
1 Answers
1
@Bean // in some config class
public JdbcMappingContext jdbcMappingContext() {
DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy();
namingStrategy.setForeignKeyNaming(ForeignKeyNaming.IGNORE_RENAMING);
return new JdbcMappingContext(namingStrategy);
}
And instead of the default plural camelcase class name as a foreign key, name it whatever you want. Just make sure the field has the same name.