Environment: Hibernate ORM 6.6.54.Final
When building the ORM model with org.hibernate.boot.MetadataBuilder, the implicit name of list index columns as specified by ImplicitNamingStrategy is not used.
A minimal example:
@Entity
public class Entity1
{
@Id
private Long id;
@ManyToMany
private List<Entity2> other;
}
@Entity
public class Entity2
{
@Id
private Long other_id;
}
public class CustomImplicitNamingStrategy extends ImplicitNamingStrategyJpaCompliantImpl
{
@Override
public Identifier determineListIndexColumnName(final ImplicitIndexColumnNameSource source)
{
return Identifier.toIdentifier("INDEX");
}
@Override
public Identifier determineJoinTableName(final ImplicitJoinTableNameSource source)
{
final String name = source.getOwningPhysicalTableName() + "_MAP_" + source.getNonOwningPhysicalTableName();
return toIdentifier( name, source.getBuildingContext() );
}
}
class ORMStandaloneTestCase {
@Test
void test() {
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
.applySetting( "hibernate.show_sql", "true" )
.applySetting( "hibernate.format_sql", "true" )
.applySetting( "hibernate.hbm2ddl.auto", "update" )
.applySetting( "hibernate.mapping.default_list_semantics", "LIST" )
.applySetting( "hibernate.implicit_naming_strategy", "org.hibernate.bugs.CustomImplicitNamingStrategy" );
Metadata metadata = new MetadataSources( srb.build() )
.addAnnotatedClass( Entity1.class )
.addAnnotatedClass( Entity2.class )
.buildMetadata();
metadata.buildSessionFactory();
}
}
Here, I expect the mapping table to have a column INDEX instead of the default index column other_ORDER. I verified that the CustomImplicitNamingStrategy is applied by overriding determineJoinTableName().
The mapping table is indeed named according to determineJoinTableName(), but the index column is still named other_ORDER.
As I debugged the issue, I think I found the cause in hibernate-orm/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java at main · hibernate/hibernate-orm · GitHub , where the default name seems to be harcoded.
Is this a bug or expected behavior?
Thanks