From 52f2c3a002b65aa530a467f4fff7b5eb50d0dd92 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 8 Oct 2014 03:13:38 -0700 Subject: [PATCH] HHH-9388 HHH-7079 : Default collection table and foreign key names are incorrect in some cases; deprecate NamingStrategy (cherry picked from commit e5a31caa09b56ace6ad4aa4ccb99a0ad63b1ad31) Conflicts: hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/MyNamingStrategyDelegator.java --- .../java/org/hibernate/cfg/Configuration.java | 3 +- .../java/org/hibernate/cfg/Ejb3Column.java | 5 +- .../org/hibernate/cfg/Ejb3JoinColumn.java | 22 +-- .../java/org/hibernate/cfg/HbmBinder.java | 18 +- .../org/hibernate/cfg/NamingStrategy.java | 3 +- .../cfg/annotations/EntityBinder.java | 2 +- .../cfg/annotations/TableBinder.java | 8 +- .../cfg/naming/HbmNamingStrategyDelegate.java | 34 ++-- ...a => ImprovedNamingStrategyDelegator.java} | 19 +- .../cfg/naming/JpaNamingStrategyDelegate.java | 40 ++-- .../LegacyHbmNamingStrategyDelegate.java | 43 +++-- ...a => LegacyJpaNamingStrategyDelegate.java} | 51 +++-- .../naming/LegacyNamingStrategyDelegate.java | 1 + ... LegacyNamingStrategyDelegateAdapter.java} | 21 +- .../naming/LegacyNamingStrategyDelegator.java | 7 +- .../cfg/naming/NamingStrategyDelegate.java | 181 ++++++++++++------ ...ava => NamingStrategyDelegateAdapter.java} | 20 +- .../cfg/naming/NamingStrategyDelegator.java | 7 +- ...mImprovedNamingCollectionElementTest.java} | 145 +++----------- ...> DefaultNamingCollectionElementTest.java} | 30 +-- ... ImprovedNamingCollectionElementTest.java} | 23 +-- .../test/annotations/manytomany/Group.java | 1 - .../annotations/manytomany/GroupWithSet.java | 1 - ....java => DefaultNamingManyToManyTest.java} | 30 +-- ...va => ImprovedManyToManyDefaultsTest.java} | 19 +- .../jpa/test/MyNamingStrategyDelegator.java | 14 +- ...ingStrategyDelegatorConfigurationTest.java | 2 +- 27 files changed, 353 insertions(+), 397 deletions(-) rename hibernate-core/src/main/java/org/hibernate/cfg/naming/{DefaultNamingStrategyDelegator.java => ImprovedNamingStrategyDelegator.java} (70%) rename hibernate-core/src/main/java/org/hibernate/cfg/naming/{LegacyStandardNamingStrategyDelegate.java => LegacyJpaNamingStrategyDelegate.java} (67%) rename hibernate-core/src/main/java/org/hibernate/cfg/naming/{AbstractLegacyNamingStrategyDelegate.java => LegacyNamingStrategyDelegateAdapter.java} (68%) rename hibernate-core/src/main/java/org/hibernate/cfg/naming/{AbstractNamingStrategyDelegate.java => NamingStrategyDelegateAdapter.java} (74%) rename hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/{CustomNamingCollectionElementTest.java => CustomImprovedNamingCollectionElementTest.java} (57%) rename hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/{CollectionElementTest.java => DefaultNamingCollectionElementTest.java} (93%) rename hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/{LegacyNamingCollectionElementTest.java => ImprovedNamingCollectionElementTest.java} (75%) rename hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/{ManyToManyDefaultsTest.java => DefaultNamingManyToManyTest.java} (91%) rename hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/{LegacyManyToManyDefaultsTest.java => ImprovedManyToManyDefaultsTest.java} (80%) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index f8a13e93da..1989d92e9f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -80,7 +80,6 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cfg.annotations.NamedEntityGraphDefinition; import org.hibernate.cfg.annotations.NamedProcedureCallDefinition; import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider; -import org.hibernate.cfg.naming.DefaultNamingStrategyDelegator; import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator; import org.hibernate.cfg.naming.NamingStrategyDelegator; import org.hibernate.context.spi.CurrentTenantIdentifierResolver; @@ -352,7 +351,7 @@ public class Configuration implements Serializable { mappedByResolver = new HashMap(); propertyRefResolver = new HashMap(); caches = new ArrayList(); - namingStrategyDelegator = DefaultNamingStrategyDelegator.INSTANCE; + namingStrategyDelegator = LegacyNamingStrategyDelegator.DEFAULT_INSTANCE; setEntityResolver( new EJB3DTDEntityResolver() ); anyMetaDefs = new HashMap(); propertiesAnnotatedWithMapsId = new HashMap>(); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3Column.java b/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3Column.java index e0a86fce95..0cfc01922f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3Column.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3Column.java @@ -293,7 +293,7 @@ public class Ejb3Column { if ( propertyName != null ) { mappingColumn.setName( mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( - getNamingStrategyDelegate().determineAttributeColumnName( propertyName ) + getNamingStrategyDelegate().determineImplicitPropertyColumnName( propertyName ) ) ); } @@ -368,7 +368,8 @@ public class Ejb3Column { } protected void addColumnBinding(SimpleValue value) { - String logicalColumnName = getNamingStrategyDelegate().logicalColumnName( this.logicalColumnName, propertyName ); + String logicalColumnName = + getNamingStrategyDelegate().determineLogicalColumnName( this.logicalColumnName, propertyName ); mappings.addColumnBinding( logicalColumnName, getMappingColumn(), value.getTable() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java b/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java index e595a1c45d..19587ba0f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java @@ -455,21 +455,21 @@ public class Ejb3JoinColumn extends Ejb3Column { if ( mappedBySide ) { String unquotedMappedbyTable = StringHelper.unquote( mappedByTableName ); if ( JPA2ElementCollection ) { - columnName = getNamingStrategyDelegate().determineElementCollectionForeignKeyColumnName( - mappedByPropertyName, + columnName = getNamingStrategyDelegate().determineImplicitElementCollectionJoinColumnName( mappedByEntityName, mappedByJpaEntityName, unquotedMappedbyTable, - unquotedLogicalReferenceColumn + unquotedLogicalReferenceColumn, + mappedByPropertyName ); } else { - columnName = getNamingStrategyDelegate().determineEntityAssociationForeignKeyColumnName( - mappedByPropertyName, + columnName = getNamingStrategyDelegate().determineImplicitEntityAssociationJoinColumnName( mappedByEntityName, mappedByJpaEntityName, unquotedMappedbyTable, - unquotedLogicalReferenceColumn + unquotedLogicalReferenceColumn, + mappedByPropertyName ); } //one element was quoted so we quote @@ -480,12 +480,12 @@ public class Ejb3JoinColumn extends Ejb3Column { else if ( ownerSide ) { String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() ); String unquotedLogicalTableName = StringHelper.unquote( logicalTableName ); - columnName = getNamingStrategyDelegate().determineEntityAssociationForeignKeyColumnName( - getPropertyName(), + columnName = getNamingStrategyDelegate().determineImplicitEntityAssociationJoinColumnName( referencedEntity.getEntityName(), referencedEntity.getJpaEntityName(), unquotedLogicalTableName, - unquotedLogicalReferenceColumn + unquotedLogicalReferenceColumn, + getPropertyName() ); //one element was quoted so we quote if ( isRefColumnQuoted || StringHelper.isQuoted( logicalTableName ) ) { @@ -496,7 +496,7 @@ public class Ejb3JoinColumn extends Ejb3Column { //is an intra-entity hierarchy table join so copy the name by default String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() ); String unquotedLogicalTableName = StringHelper.unquote( logicalTableName ); - columnName = getNamingStrategyDelegate().determineJoinKeyColumnName( + columnName = getNamingStrategyDelegate().toPhysicalJoinKeyColumnName( unquotedLogicalReferenceColumn, unquotedLogicalTableName ); @@ -538,7 +538,7 @@ public class Ejb3JoinColumn extends Ejb3Column { final String referencedColumn = nameNormalizer.normalizeIdentifierQuoting( getReferencedColumn() ); final String unquotedLogColName = StringHelper.unquote( logicalColumnName ); final String unquotedRefColumn = StringHelper.unquote( referencedColumn ); - String logicalCollectionColumnName = getNamingStrategyDelegate().logicalCollectionColumnName( + String logicalCollectionColumnName = getNamingStrategyDelegate().determineLogicalCollectionColumnName( unquotedLogColName, getPropertyName(), unquotedRefColumn diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java index d5b2120bee..089aef0d8d 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java @@ -889,7 +889,7 @@ public final class HbmBinder { String physicalTableName; if ( tableNameNode == null ) { logicalTableName = StringHelper.unqualify( model.getEntityName() ); - physicalTableName = getNamingStrategyDelegate( mappings ).determinePrimaryTableLogicalName( + physicalTableName = getNamingStrategyDelegate( mappings ).determineImplicitPrimaryTableName( model.getEntityName(), model.getJpaEntityName() ); @@ -1081,7 +1081,7 @@ public final class HbmBinder { column.setTypeIndex( count++ ); bindColumn( columnElement, column, isNullable ); String columnName = columnElement.attributeValue( "name" ); - String logicalColumnName = getNamingStrategyDelegate( mappings ).logicalColumnName( + String logicalColumnName = getNamingStrategyDelegate( mappings ).determineLogicalColumnName( columnName, propertyPath ); columnName = getNamingStrategyDelegate( mappings ).toPhysicalColumnName( columnName ); @@ -1137,7 +1137,7 @@ public final class HbmBinder { ( (ManyToOne) simpleValue ).markAsLogicalOneToOne(); } String columnName = columnAttribute.getValue(); - String logicalColumnName = getNamingStrategyDelegate( mappings ).logicalColumnName( + String logicalColumnName = getNamingStrategyDelegate( mappings ).determineLogicalColumnName( columnName, propertyPath ); columnName = getNamingStrategyDelegate( mappings ).toPhysicalColumnName( columnName ); @@ -1158,10 +1158,10 @@ public final class HbmBinder { Column column = new Column(); column.setValue( simpleValue ); bindColumn( node, column, isNullable ); - String columnName = getNamingStrategyDelegate( mappings ).determineAttributeColumnName( propertyPath ); + String columnName = getNamingStrategyDelegate( mappings ).determineImplicitPropertyColumnName( propertyPath ); columnName = quoteIdentifier( columnName, mappings ); column.setName( columnName ); - String logicalName = getNamingStrategyDelegate( mappings ).logicalColumnName( null, propertyPath ); + String logicalName = getNamingStrategyDelegate( mappings ).determineLogicalColumnName( null, propertyPath ); mappings.addColumnBinding( logicalName, column, table ); /* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a * slightly higer level in the stack (to get all the information we need) @@ -1499,16 +1499,16 @@ public final class HbmBinder { String logicalOwnerTableName = ownerTable.getName(); //FIXME we don't have the associated entity table name here, has to be done in a second pass if ( node.element( "element" ) != null || node.element( "composite-element" ) != null ) { - tableName = getNamingStrategyDelegate( mappings ).determineElementCollectionTableLogicalName( + tableName = getNamingStrategyDelegate( mappings ).determineImplicitElementCollectionTableName( collection.getOwner().getClassName(), - collection.getOwner().getEntityName(), + collection.getOwner().getJpaEntityName(), logicalOwnerTableName, path ); } else { - tableName = getNamingStrategyDelegate( mappings ).determineEntityAssociationJoinTableLogicalName( - collection.getOwner().getEntityName(), + tableName = getNamingStrategyDelegate( mappings ).determineImplicitEntityAssociationJoinTableName( + collection.getOwner().getClassName(), collection.getOwner().getJpaEntityName(), logicalOwnerTableName, null, diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/NamingStrategy.java b/hibernate-core/src/main/java/org/hibernate/cfg/NamingStrategy.java index 9c1d4a53b3..d0cc7b7221 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/NamingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/NamingStrategy.java @@ -38,8 +38,9 @@ package org.hibernate.cfg; * @author Gavin King * @author Emmanuel Bernard * - * @deprecated + * @deprecated A {@link org.hibernate.cfg.naming.NamingStrategyDelegator} should be used instead. */ +@Deprecated public interface NamingStrategy { /** * Return a table name for an entity class diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java index af52045c58..0090734084 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java @@ -563,7 +563,7 @@ public class EntityBinder { @Override public String determineImplicitName(NamingStrategyDelegator strategyDelegator) { - return getNamingStrategyDelegate( strategyDelegator ).determinePrimaryTableLogicalName( + return getNamingStrategyDelegate( strategyDelegator ).determineImplicitPrimaryTableName( entityName, jpaEntityName ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java index 1810726875..68d0b9d42d 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java @@ -180,7 +180,7 @@ public class TableBinder { final NamingStrategyDelegate strategyDelegate = getNamingStrategyDelegate( strategyDelegator ); final String strategyResult; if ( isJPA2ElementCollection ) { - strategyResult = strategyDelegate.determineElementCollectionTableLogicalName( + strategyResult = strategyDelegate.determineImplicitElementCollectionTableName( ownerEntity, ownerJpaEntity, unquotedOwnerTable, @@ -188,7 +188,7 @@ public class TableBinder { ); } else { - strategyResult = strategyDelegate.determineEntityAssociationJoinTableLogicalName( + strategyResult = strategyDelegate.determineImplicitEntityAssociationJoinTableName( ownerEntity, ownerJpaEntity, unquotedOwnerTable, @@ -232,7 +232,7 @@ public class TableBinder { ); String logicalName; if ( isJPA2ElementCollection ) { - logicalName = strategyDelegate.logicalElementCollectionTableName( + logicalName = strategyDelegate.determineLogicalElementCollectionTableName( name, ownerEntity, ownerJpaEntity, @@ -241,7 +241,7 @@ public class TableBinder { ); } else { - logicalName = strategyDelegate.logicalEntityAssociationJoinTableName( + logicalName = strategyDelegate.determineLogicalEntityAssociationJoinTableName( name, ownerEntity, ownerJpaEntity, diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/HbmNamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/HbmNamingStrategyDelegate.java index b8f6e466cf..df7feb04b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/HbmNamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/HbmNamingStrategyDelegate.java @@ -28,55 +28,51 @@ import org.hibernate.internal.util.StringHelper; /** * @author Gail Badner */ -public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate { +public class HbmNamingStrategyDelegate extends NamingStrategyDelegateAdapter { @Override - public String determinePrimaryTableLogicalName(String entityName, String jpaEntityName) { + public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName) { return StringHelper.unqualify( entityName ); } @Override - public String determineElementCollectionTableLogicalName( + public String determineImplicitElementCollectionTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, - String propertyNamePath) { + String propertyPath) { return ownerEntityTable + '_' - + StringHelper.unqualify( propertyNamePath ); + + StringHelper.unqualify( propertyPath ); } @Override - public String determineElementCollectionForeignKeyColumnName(String propertyName, String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName) { + public String determineImplicitElementCollectionJoinColumnName(String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String referencedColumnName, String propertyPath) { throw new UnsupportedOperationException( "Method not supported for Hibernate-specific mappings" ); } @Override - public String determineEntityAssociationJoinTableLogicalName( + public String determineImplicitEntityAssociationJoinTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String associatedEntityName, String associatedJpaEntityName, String associatedEntityTable, - String propertyNamePath) { + String propertyPath) { return ownerEntityTable + '_' - + StringHelper.unqualify( propertyNamePath ); + + StringHelper.unqualify( propertyPath ); } @Override - public String determineEntityAssociationForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { + public String determineImplicitEntityAssociationJoinColumnName( + String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String propertyPath) { throw new UnsupportedOperationException( "Method not supported for Hibernate-specific mappings" ); } @Override - public String logicalElementCollectionTableName( + public String determineLogicalElementCollectionTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, @@ -86,7 +82,7 @@ public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate { return tableName; } else { - return determineElementCollectionTableLogicalName( + return determineImplicitElementCollectionTableName( ownerEntityName, ownerJpaEntityName, ownerEntityTable, @@ -96,7 +92,7 @@ public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate { } @Override - public String logicalEntityAssociationJoinTableName( + public String determineLogicalEntityAssociationJoinTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, @@ -109,7 +105,7 @@ public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate { return tableName; } else { - return determineEntityAssociationJoinTableLogicalName( + return determineImplicitEntityAssociationJoinTableName( ownerEntityName, ownerJpaEntityName, ownerEntityTable, diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/DefaultNamingStrategyDelegator.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/ImprovedNamingStrategyDelegator.java similarity index 70% rename from hibernate-core/src/main/java/org/hibernate/cfg/naming/DefaultNamingStrategyDelegator.java rename to hibernate-core/src/main/java/org/hibernate/cfg/naming/ImprovedNamingStrategyDelegator.java index 38e46c0cc4..9f5adb4009 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/DefaultNamingStrategyDelegator.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/ImprovedNamingStrategyDelegator.java @@ -28,15 +28,24 @@ import java.io.Serializable; /** * @author Gail Badner */ -public class DefaultNamingStrategyDelegator implements NamingStrategyDelegator, Serializable { - public static final DefaultNamingStrategyDelegator INSTANCE = new DefaultNamingStrategyDelegator(); +public class ImprovedNamingStrategyDelegator implements NamingStrategyDelegator, Serializable { + public static final NamingStrategyDelegator DEFAULT_INSTANCE = new ImprovedNamingStrategyDelegator(); private final NamingStrategyDelegate hbmNamingStrategyDelegate; private final NamingStrategyDelegate jpaNamingStrategyDelegate; - private DefaultNamingStrategyDelegator() { - this.hbmNamingStrategyDelegate = new HbmNamingStrategyDelegate(); - this.jpaNamingStrategyDelegate = new JpaNamingStrategyDelegate(); + private ImprovedNamingStrategyDelegator() { + this( + new HbmNamingStrategyDelegate(), + new JpaNamingStrategyDelegate() + ); + } + + protected ImprovedNamingStrategyDelegator( + NamingStrategyDelegate hbmNamingStrategyDelegate, + NamingStrategyDelegate jpaNamingStrategyDelegate) { + this.hbmNamingStrategyDelegate = hbmNamingStrategyDelegate; + this.jpaNamingStrategyDelegate = jpaNamingStrategyDelegate; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/JpaNamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/JpaNamingStrategyDelegate.java index 653de66ca6..6c0e68a766 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/JpaNamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/JpaNamingStrategyDelegate.java @@ -29,19 +29,19 @@ import org.hibernate.internal.util.StringHelper; /** * @author Gail Badner */ -public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { +public class JpaNamingStrategyDelegate extends NamingStrategyDelegateAdapter { @Override - public String determinePrimaryTableLogicalName(String entityName, String jpaEntityName) { + public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName) { return StringHelper.unqualify( determineEntityNameToUse( entityName, jpaEntityName ) ); } @Override - public String determineElementCollectionTableLogicalName( + public String determineImplicitElementCollectionTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, - String propertyNamePath) { + String propertyPath) { // JPA states we should use the following as default: // "The concatenation of the name of the containing entity and the name of the // collection attribute, separated by an underscore. @@ -50,33 +50,29 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { // otherwise: {OWNER ENTITY NAME}_{COLLECTION ATTRIBUTE NAME} return determineEntityNameToUse( ownerEntityName, ownerJpaEntityName ) + '_' - + StringHelper.unqualify( propertyNamePath ); + + StringHelper.unqualify( propertyPath ); } @Override - public String determineElementCollectionForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { + public String determineImplicitElementCollectionJoinColumnName( + String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String referencedColumnName, String propertyPath) { // JPA states we should use the following as default: // "The concatenation of the following: the name of the entity; "_"; the name of the // referenced primary key column" - return determineEntityNameToUse( propertyEntityName, propertyJpaEntityName ) + return determineEntityNameToUse( ownerEntityName, ownerJpaEntityName ) + '_' + referencedColumnName; } @Override - public String determineEntityAssociationJoinTableLogicalName( + public String determineImplicitEntityAssociationJoinTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String associatedEntityName, String associatedJpaEntityName, String associatedEntityTable, - String propertyNamePath) { + String propertyPath) { // JPA states we should use the following as default: // "The concatenated names of the two associated primary entity tables (owning side // first), separated by an underscore." @@ -89,12 +85,8 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { } @Override - public String determineEntityAssociationForeignKeyColumnName( - String referencingPropertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { + public String determineImplicitEntityAssociationJoinColumnName( + String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String referencingPropertyName) { // JPA states we should use the following as default: // "The concatenation of the following: the name of the referencing relationship // property or field of the referencing entity or embeddable class; "_"; the name @@ -125,7 +117,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { } @Override - public String logicalElementCollectionTableName( + public String determineLogicalElementCollectionTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, @@ -135,7 +127,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { return tableName; } else { - return determineElementCollectionTableLogicalName( + return determineImplicitElementCollectionTableName( ownerEntityName, ownerJpaEntityName, ownerEntityTable, @@ -145,7 +137,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { } @Override - public String logicalEntityAssociationJoinTableName( + public String determineLogicalEntityAssociationJoinTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, @@ -158,7 +150,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { return tableName; } else { - return determineEntityAssociationJoinTableLogicalName( + return determineImplicitEntityAssociationJoinTableName( ownerEntityName, ownerJpaEntityName, ownerEntityTable, diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyHbmNamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyHbmNamingStrategyDelegate.java index 2a75f793e8..f9dc61c0c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyHbmNamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyHbmNamingStrategyDelegate.java @@ -26,64 +26,67 @@ package org.hibernate.cfg.naming; /** * @author Gail Badner */ -public class LegacyHbmNamingStrategyDelegate extends AbstractLegacyNamingStrategyDelegate { +@Deprecated +public class LegacyHbmNamingStrategyDelegate extends LegacyNamingStrategyDelegateAdapter { public LegacyHbmNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { super( context ); } @Override - public String determineElementCollectionTableLogicalName( + public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName) { + return getNamingStrategy().classToTableName( entityName ); + } + + @Override + public String determineImplicitElementCollectionTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, - String propertyNamePath) { + String propertyPath) { return getNamingStrategy().collectionTableName( ownerEntityName, ownerEntityTable, null, null, - propertyNamePath + propertyPath ); } @Override - public String determineElementCollectionForeignKeyColumnName(String propertyName, String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName) { + public String determineImplicitElementCollectionJoinColumnName( + String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String referencedColumnName, String propertyPath) { return getNamingStrategy().foreignKeyColumnName( - propertyName, - propertyEntityName, - propertyTableName, + propertyPath, + ownerEntityName, + ownerEntityTable, referencedColumnName ); } @Override - public String determineEntityAssociationJoinTableLogicalName( + public String determineImplicitEntityAssociationJoinTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String associatedEntityName, String associatedJpaEntityName, String associatedEntityTable, - String propertyNamePath) { + String propertyPath) { return getNamingStrategy().collectionTableName( ownerEntityName, ownerEntityTable, associatedEntityName, associatedEntityTable, - propertyNamePath + propertyPath ); } @Override - public String determineEntityAssociationForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { + public String determineImplicitEntityAssociationJoinColumnName( + String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String propertyPath) { return getNamingStrategy().foreignKeyColumnName( - propertyName, + propertyPath, propertyEntityName, propertyTableName, referencedColumnName @@ -91,7 +94,7 @@ public class LegacyHbmNamingStrategyDelegate extends AbstractLegacyNamingStrateg } @Override - public String logicalElementCollectionTableName( + public String determineLogicalElementCollectionTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, @@ -106,7 +109,7 @@ public class LegacyHbmNamingStrategyDelegate extends AbstractLegacyNamingStrateg } @Override - public String logicalEntityAssociationJoinTableName( + public String determineLogicalEntityAssociationJoinTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyStandardNamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyJpaNamingStrategyDelegate.java similarity index 67% rename from hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyStandardNamingStrategyDelegate.java rename to hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyJpaNamingStrategyDelegate.java index 57e5e080a6..45aff669b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyStandardNamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyJpaNamingStrategyDelegate.java @@ -28,69 +28,68 @@ import org.hibernate.internal.util.StringHelper; /** * @author Gail Badner */ -public class LegacyStandardNamingStrategyDelegate extends AbstractLegacyNamingStrategyDelegate { +@Deprecated +public class LegacyJpaNamingStrategyDelegate extends LegacyNamingStrategyDelegateAdapter { - LegacyStandardNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { + LegacyJpaNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { super( context ); } @Override - public String determineElementCollectionTableLogicalName( + public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName) { + // jpaEntityname is being passed here in order to not cause a regression. See HHH-4312. + return getNamingStrategy().classToTableName( jpaEntityName ); + } + + @Override + public String determineImplicitElementCollectionTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, - String propertyNamePath) { + String propertyPath) { return getNamingStrategy().collectionTableName( ownerEntityName, StringHelper.unqualifyEntityName( ownerEntityName ), null, null, - propertyNamePath + propertyPath ); } @Override - public String determineElementCollectionForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { + public String determineImplicitElementCollectionJoinColumnName( + String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String referencedColumnName, String propertyPath) { return getNamingStrategy().foreignKeyColumnName( - propertyName, - propertyEntityName, - StringHelper.unqualifyEntityName( propertyEntityName ), + propertyPath, + ownerEntityName, + StringHelper.unqualifyEntityName( ownerEntityName ), referencedColumnName ); } @Override - public String determineEntityAssociationJoinTableLogicalName( + public String determineImplicitEntityAssociationJoinTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String associatedEntityName, String associatedJpaEntityName, String associatedEntityTable, - String propertyNamePath) { + String propertyPath) { return getNamingStrategy().collectionTableName( ownerEntityName, ownerEntityTable, associatedEntityName, associatedEntityTable, - propertyNamePath + propertyPath ); } @Override - public String determineEntityAssociationForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { + public String determineImplicitEntityAssociationJoinColumnName( + String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String propertyPath) { return getNamingStrategy().foreignKeyColumnName( - propertyName, + propertyPath, propertyEntityName, propertyTableName, referencedColumnName @@ -98,7 +97,7 @@ public class LegacyStandardNamingStrategyDelegate extends AbstractLegacyNamingSt } @Override - public String logicalElementCollectionTableName( + public String determineLogicalElementCollectionTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, @@ -113,7 +112,7 @@ public class LegacyStandardNamingStrategyDelegate extends AbstractLegacyNamingSt } @Override - public String logicalEntityAssociationJoinTableName( + public String determineLogicalEntityAssociationJoinTableName( String tableName, String ownerEntityName, String ownerJpaEntityName, diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegate.java index 1a33e95ccb..5d33748784 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegate.java @@ -28,6 +28,7 @@ import org.hibernate.cfg.NamingStrategy; /** * @author Gail Badner */ +@Deprecated public interface LegacyNamingStrategyDelegate extends NamingStrategyDelegate { public static interface LegacyNamingStrategyDelegateContext { public NamingStrategy getNamingStrategy(); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/AbstractLegacyNamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegateAdapter.java similarity index 68% rename from hibernate-core/src/main/java/org/hibernate/cfg/naming/AbstractLegacyNamingStrategyDelegate.java rename to hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegateAdapter.java index 6f5355dd8d..da2fec0e2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/AbstractLegacyNamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegateAdapter.java @@ -30,10 +30,11 @@ import org.hibernate.cfg.NamingStrategy; /** * @author Gail Badner */ -public abstract class AbstractLegacyNamingStrategyDelegate implements NamingStrategyDelegate, Serializable { +@Deprecated +public abstract class LegacyNamingStrategyDelegateAdapter implements NamingStrategyDelegate, Serializable { private final LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context; - public AbstractLegacyNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { + public LegacyNamingStrategyDelegateAdapter(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { this.context = context; } @@ -41,12 +42,6 @@ public abstract class AbstractLegacyNamingStrategyDelegate implements NamingStra return context.getNamingStrategy(); } - @Override - public String determinePrimaryTableLogicalName(String entityName, String jpaEntityName) { - // jpaEntity name is being passed here in order to not cause a regression. See HHH-4312. - return getNamingStrategy().classToTableName( jpaEntityName ); - } - @Override public String toPhysicalTableName(String tableName) { return getNamingStrategy().tableName( tableName ); @@ -58,22 +53,22 @@ public abstract class AbstractLegacyNamingStrategyDelegate implements NamingStra } @Override - public String determineAttributeColumnName(String propertyName) { - return getNamingStrategy().propertyToColumnName( propertyName ); + public String determineImplicitPropertyColumnName(String propertyPath) { + return getNamingStrategy().propertyToColumnName( propertyPath ); } @Override - public String determineJoinKeyColumnName(String joinedColumn, String joinedTable) { + public String toPhysicalJoinKeyColumnName(String joinedColumn, String joinedTable) { return getNamingStrategy().joinKeyColumnName( joinedColumn, joinedTable ); } @Override - public String logicalColumnName(String columnName, String propertyName) { + public String determineLogicalColumnName(String columnName, String propertyName) { return getNamingStrategy().logicalColumnName( columnName, propertyName ); } @Override - public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { + public String determineLogicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { return getNamingStrategy().logicalCollectionColumnName( columnName, propertyName, referencedColumn ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegator.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegator.java index 35a32ea726..af6db597c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegator.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/LegacyNamingStrategyDelegator.java @@ -31,7 +31,6 @@ import org.hibernate.cfg.NamingStrategy; import static org.hibernate.cfg.naming.LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext; /** - * * @deprecated Needed as a transitory implementation until the deprecated NamingStrategy contract * can be removed. * @@ -40,18 +39,20 @@ import static org.hibernate.cfg.naming.LegacyNamingStrategyDelegate.LegacyNaming @Deprecated public class LegacyNamingStrategyDelegator implements NamingStrategyDelegator, LegacyNamingStrategyDelegateContext, Serializable { + public static final NamingStrategyDelegator DEFAULT_INSTANCE = new LegacyNamingStrategyDelegator(); + private final NamingStrategy namingStrategy; private final NamingStrategyDelegate hbmNamingStrategyDelegate; private final NamingStrategyDelegate jpaNamingStrategyDelegate; - public LegacyNamingStrategyDelegator() { + private LegacyNamingStrategyDelegator() { this( EJB3NamingStrategy.INSTANCE ); } public LegacyNamingStrategyDelegator(NamingStrategy namingStrategy) { this.namingStrategy = namingStrategy; this.hbmNamingStrategyDelegate = new LegacyHbmNamingStrategyDelegate( this ); - this.jpaNamingStrategyDelegate = new LegacyStandardNamingStrategyDelegate( this ); + this.jpaNamingStrategyDelegate = new LegacyJpaNamingStrategyDelegate( this ); } public NamingStrategy getNamingStrategy() { diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegate.java index de204ff000..bc402e203f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegate.java @@ -24,13 +24,137 @@ package org.hibernate.cfg.naming; /** + * A * @author Gail Badner */ public interface NamingStrategyDelegate { - public String determinePrimaryTableLogicalName(String entityName, String jpaEntityName); + /** + * Determine the name of a entity's primary table when a name is not explicitly configured. + * + * @param entityName The fully qualified entity name + * @param jpaEntityName The entity name provided by the {@link javax.persistence.Entity} + * {@code name} attribute; or, if not mapped in this way, then the + * unqualified entity name. + * + * @return The implicit table name. + */ + public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName); - public String determineAttributeColumnName(String propertyName); + /** + * Determine the name of a property's column when a name is not explicitly configured. + * + * @param propertyPath The property path (not qualified by the entity name) + * @return The implicit column name. + */ + public String determineImplicitPropertyColumnName(String propertyPath); + + /** + * Determine the name of a collection table for a collection of (non-entity) values + * when a name is not explicitly configured. + * + * @param ownerEntityName The fully qualified entity name for the entity that owns the collection. + * @param ownerJpaEntityName The entity name provided by the {@link javax.persistence.Entity} + * {@code name} attribute for the entity that owns the collection; + * or, if not mapped in this way, then the unqualified owner entity name. + * @param ownerEntityTable The owner entity's physical primary table name; + * @param propertyPath The property path (not qualified by the entity name), + * @return The implicit table name. + */ + public String determineImplicitElementCollectionTableName( + String ownerEntityName, + String ownerJpaEntityName, + String ownerEntityTable, + String propertyPath); + + /** + * Determine the name of the join column in a collection table for + * a collection of (non-entity) values when a name is not explicitly configured. + * + * @param ownerEntityName The fully qualified name of the entity that owns the collection. + * @param ownerJpaEntityName The entity name provided by the {@link javax.persistence.Entity} + * {@code name} attribute for the entity that owns the collection; + * or, if not mapped in this way, then the unqualified entity name. + * @param ownerEntityTable The owner entity's physical primary table name; + * @param referencedColumnName The physical name of the column that the join column references. + * @param propertyPath The property path (not qualified by the entity name), + * @return The implicit column name. + */ + public String determineImplicitElementCollectionJoinColumnName( + String ownerEntityName, + String ownerJpaEntityName, + String ownerEntityTable, + String referencedColumnName, + String propertyPath); + + /** + * Determine the name of the join table for an entity (singular or plural) association when + * a name is not explicitly configured. + * + * @param ownerEntityName The fully qualified name of the entity that owns the association;. + * @param ownerJpaEntityName The entity name provided by the {@link javax.persistence.Entity} + * {@code name} attribute for the entity that owns the association; + * or, if not mapped in this way, then the unqualified owner entity name. + * @param ownerEntityTable The owner entity's physical primary table name; + * @param associatedEntityName The fully qualified name of the associated entity. + * @param associatedJpaEntityName The entity name provided by the {@link javax.persistence.Entity} + * {@code name} attribute for the associated entity; + * or, if not mapped in this way, then the unqualified associated entity name. + * @param associatedEntityTable The associated entity's physical primary table name; + * @param propertyPath The property path (not qualified by the entity name), + * @return The implicit table name. + */ + public String determineImplicitEntityAssociationJoinTableName( + String ownerEntityName, + String ownerJpaEntityName, + String ownerEntityTable, + String associatedEntityName, + String associatedJpaEntityName, + String associatedEntityTable, + String propertyPath); + + /** + * Determine the name of join column for an entity (singular or plural) association when + * a name is not explicitly configured. + * + * @param propertyEntityName The fully qualified name of the entity that contains the association; + * @param propertyJpaEntityName The entity name provided by the {@link javax.persistence.Entity} + * {@code name} attribute for the entity that contains the association; + * or, if not mapped in this way, then the unqualified entity name. + * @param propertyTableName The physical primary table name for the entity that contains the association. + * @param referencedColumnName The physical name of the column that the join column references. + * @param propertyPath The property path (not qualified by the entity name), + * @return The implicit table name. + */ + public String determineImplicitEntityAssociationJoinColumnName( + String propertyEntityName, + String propertyJpaEntityName, + String propertyTableName, + String referencedColumnName, + String propertyPath); + + public String toPhysicalJoinKeyColumnName(String joinedColumn, String joinedTable); + + public String determineLogicalColumnName(String columnName, String propertyName); + + public String determineLogicalElementCollectionTableName( + String tableName, + String ownerEntityName, + String ownerJpaEntityName, + String ownerEntityTable, + String propertyName); + + public String determineLogicalEntityAssociationJoinTableName( + String tableName, + String ownerEntityName, + String ownerJpaEntityName, + String ownerEntityTable, + String associatedEntityName, + String associatedJpaEntityName, + String associatedEntityTable, + String propertyName); + + public String determineLogicalCollectionColumnName(String columnName, String propertyName, String referencedColumn); /** * Alter the table name given in the mapping document @@ -46,57 +170,4 @@ public interface NamingStrategyDelegate { */ public String toPhysicalColumnName(String columnName); - - public String determineElementCollectionTableLogicalName( - String ownerEntityName, - String ownerJpaEntityName, - String ownerEntityTable, - String propertyName); - - public String determineElementCollectionForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName); - - - public String determineEntityAssociationJoinTableLogicalName( - String ownerEntityName, - String ownerJpaEntityName, - String ownerEntityTable, - String associatedEntityName, - String associatedJpaEntityName, - String associatedEntityTable, - String propertyName); - - public String determineEntityAssociationForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName); - - public String determineJoinKeyColumnName(String joinedColumn, String joinedTable); - - public String logicalColumnName(String columnName, String propertyName); - - public String logicalElementCollectionTableName( - String tableName, - String ownerEntityName, - String ownerJpaEntityName, - String ownerEntityTable, - String propertyName); - - public String logicalEntityAssociationJoinTableName( - String tableName, - String ownerEntityName, - String ownerJpaEntityName, - String ownerEntityTable, - String associatedEntityName, - String associatedJpaEntityName, - String associatedEntityTable, - String propertyName); - - public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/AbstractNamingStrategyDelegate.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegateAdapter.java similarity index 74% rename from hibernate-core/src/main/java/org/hibernate/cfg/naming/AbstractNamingStrategyDelegate.java rename to hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegateAdapter.java index 871527e79e..e06bd2d428 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/AbstractNamingStrategyDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegateAdapter.java @@ -28,9 +28,16 @@ import java.io.Serializable; import org.hibernate.internal.util.StringHelper; /** + * An "adapter" for {@link NamingStrategyDelegate} implementations to extend. + * * @author Gail Badner */ -public abstract class AbstractNamingStrategyDelegate implements NamingStrategyDelegate, Serializable { +public abstract class NamingStrategyDelegateAdapter implements NamingStrategyDelegate, Serializable { + + @Override + public String determineImplicitPropertyColumnName(String propertyPath) { + return StringHelper.unqualify( propertyPath ); + } @Override public String toPhysicalTableName(String tableName) { @@ -43,22 +50,17 @@ public abstract class AbstractNamingStrategyDelegate implements NamingStrategyDe } @Override - public String determineAttributeColumnName(String propertyName) { - return StringHelper.unqualify( propertyName ); - } - - @Override - public String determineJoinKeyColumnName(String joinedColumn, String joinedTable) { + public String toPhysicalJoinKeyColumnName(String joinedColumn, String joinedTable) { return toPhysicalColumnName( joinedColumn ); } @Override - public String logicalColumnName(String columnName, String propertyName) { + public String determineLogicalColumnName(String columnName, String propertyName) { return StringHelper.isNotEmpty( columnName ) ? columnName : StringHelper.unqualify( propertyName ); } @Override - public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { + public String determineLogicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { return StringHelper.isNotEmpty( columnName ) ? columnName : StringHelper.unqualify( propertyName ) + "_" + referencedColumn; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegator.java b/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegator.java index d13764acb2..bb4682b2af 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegator.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/naming/NamingStrategyDelegator.java @@ -23,12 +23,13 @@ */ package org.hibernate.cfg.naming; -import org.hibernate.cfg.NamingStrategy; - /** - * Provides access to the appropriate {@link NamingStrategyDelegate}. + * Provides access to the appropriate {@link NamingStrategyDelegate}, depending on whether a + * mapping is Hibernate-specific (i.e., hbm.xml). * * @author Gail Badner + * + * @see org.hibernate.cfg.naming.NamingStrategyDelegate */ public interface NamingStrategyDelegator { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomNamingCollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomImprovedNamingCollectionElementTest.java similarity index 57% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomNamingCollectionElementTest.java rename to hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomImprovedNamingCollectionElementTest.java index bad57f1f03..984dd131c5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomNamingCollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CustomImprovedNamingCollectionElementTest.java @@ -26,24 +26,20 @@ package org.hibernate.test.annotations.collectionelement; import org.junit.Test; import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.EJB3NamingStrategy; -import org.hibernate.cfg.NamingStrategy; -import org.hibernate.cfg.naming.AbstractLegacyNamingStrategyDelegate; -import org.hibernate.cfg.naming.LegacyHbmNamingStrategyDelegate; -import org.hibernate.cfg.naming.LegacyNamingStrategyDelegate; -import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator; -import org.hibernate.cfg.naming.NamingStrategyDelegate; +import org.hibernate.cfg.naming.HbmNamingStrategyDelegate; +import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator; +import org.hibernate.cfg.naming.JpaNamingStrategyDelegate; import org.hibernate.testing.TestForIssue; /** * @author Gail Badner */ -public class CustomNamingCollectionElementTest extends CollectionElementTest { +public class CustomImprovedNamingCollectionElementTest extends ImprovedNamingCollectionElementTest { @Override public void configure(Configuration cfg) { super.configure( cfg ); - cfg.setNamingStrategyDelegator( new MyLegacyNamingStrategyDelegator() ); + cfg.setNamingStrategyDelegator( new MyImprovedNamingStrategyDelegator() ); } @Test @@ -114,131 +110,38 @@ public class CustomNamingCollectionElementTest extends CollectionElementTest { checkDefaultCollectionTableName( Boy.class, "hatedNames", "tbl_Boys_hatedNames" ); } - static class MyLegacyNamingStrategyDelegator extends LegacyNamingStrategyDelegator { - private final NamingStrategyDelegate hbmNamingStrategyDelegate = new LegacyHbmNamingStrategyDelegate( this ); - private final NamingStrategyDelegate nonHbmNamingStrategyDelegate = new MyNonHbmNamingStrategyDelegator( this ); - - @Override - public NamingStrategyDelegate getNamingStrategyDelegate(boolean isHbm) { - return isHbm ? hbmNamingStrategyDelegate : nonHbmNamingStrategyDelegate; + static class MyImprovedNamingStrategyDelegator extends ImprovedNamingStrategyDelegator { + public MyImprovedNamingStrategyDelegator() { + super( new HbmNamingStrategyDelegate(), new MyNonHbmNamingStrategyDelegate() ); } - @Override - public NamingStrategy getNamingStrategy() { - return EJB3NamingStrategy.INSTANCE; - } - - private class MyNonHbmNamingStrategyDelegator extends AbstractLegacyNamingStrategyDelegate { - MyNonHbmNamingStrategyDelegator(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { - super( context ); - } - + private static class MyNonHbmNamingStrategyDelegate extends JpaNamingStrategyDelegate { @Override - public String toPhysicalTableName(String tableName) { - return getNamingStrategy().tableName( tableName ); - } - - @Override - public String toPhysicalColumnName(String columnName) { - return getNamingStrategy().columnName( columnName ); - } - - @Override - public String determineElementCollectionTableLogicalName( + public String determineImplicitElementCollectionTableName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, - String propertyNamePath) { - return getNamingStrategy().collectionTableName( - ownerEntityName, - ownerEntityTable, - null, - null, - propertyNamePath - ); + String propertyPath) { + // This impl uses the owner entity table name instead of the JPA entity name when + // generating the implicit name. + int loc = propertyPath.lastIndexOf("."); + final String unqualifiedPropertyName = loc < 0 ? propertyPath : propertyPath.substring( loc + 1 ); + return ownerEntityTable + + '_' + + unqualifiedPropertyName; } @Override - public String determineElementCollectionForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { - return getNamingStrategy().foreignKeyColumnName( - propertyName, - propertyEntityName, - propertyTableName, - referencedColumnName - ); - } - - @Override - public String determineEntityAssociationJoinTableLogicalName( + public String determineImplicitElementCollectionJoinColumnName( String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, - String associatedEntityName, - String associatedJpaEntityName, - String associatedEntityTable, - String propertyNamePath) { - return getNamingStrategy().collectionTableName( - ownerEntityName, - ownerEntityTable, - associatedEntityName, - associatedEntityTable, - propertyNamePath - ); - } - - @Override - public String determineEntityAssociationForeignKeyColumnName( - String propertyName, - String propertyEntityName, - String propertyJpaEntityName, - String propertyTableName, - String referencedColumnName) { - return getNamingStrategy().foreignKeyColumnName( - propertyName, - propertyEntityName, - propertyTableName, - referencedColumnName - ); - } - - @Override - public String logicalElementCollectionTableName( - String tableName, - String ownerEntityName, - String ownerJpaEntityName, - String ownerEntityTable, - String propertyName) { - return getNamingStrategy().logicalCollectionTableName( - tableName, - ownerEntityTable, - null, - propertyName - ); - } - - @Override - public String logicalEntityAssociationJoinTableName( - String tableName, - String ownerEntityName, - String ownerJpaEntityName, - String ownerEntityTable, - String associatedEntityName, - String associatedJpaEntityName, - String associatedEntityTable, - String propertyName) { - return getNamingStrategy().logicalCollectionTableName( - tableName, - ownerEntityTable, - associatedEntityTable, - propertyName - ); + String referencedColumnName, + String propertyPath) { + return ownerEntityTable + + '_' + + referencedColumnName; } } } - } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/DefaultNamingCollectionElementTest.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java rename to hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/DefaultNamingCollectionElementTest.java index 79525aa978..1cff724362 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/DefaultNamingCollectionElementTest.java @@ -47,11 +47,16 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** + * Tests @ElementCollection using the default "legacy" NamingStrategyDelegator which does not + * comply with JPA spec in some cases. See HHH-9387 and HHH-9389 for more information.. + * * @author Emmanuel Bernard * @author Hardy Ferentschik + * @author Gail Badner */ @SuppressWarnings("unchecked") -public class CollectionElementTest extends BaseCoreFunctionalTestCase { +public class DefaultNamingCollectionElementTest extends BaseCoreFunctionalTestCase { + @Test public void testSimpleElement() throws Exception { assertEquals( @@ -274,7 +279,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase { assertTrue( "Could not find " + columnName, hasDefault ); } - @Test @TestForIssue( jiraKey = "HHH-9387") public void testDefaultTableNameNoOverrides() { @@ -302,18 +306,19 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase { // to ensure that entity names/tables are not changed (which would invalidate these test cases). // Matrix has @Entity(name="Mtx"); entity table name defaults to "Mtx"; owner PK column is configured as "mId" - checkDefaultCollectionTableName( Matrix.class, "mvalues", "Mtx_mvalues" ); + // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated collection table. + checkDefaultCollectionTableName( Matrix.class, "mvalues", "Matrix_mvalues" ); } @Test - @TestForIssue( jiraKey = "HHH-9387") - public void testDefaultTableNameOwnerPrimaryTableAndEntityNamesOverride() { + @TestForIssue( jiraKey = "HHH-9389") + public void testDefaultJoinColumnOwnerPrimaryTableAndEntityNamesOverride() { // NOTE: expected JPA entity names are explicit here (rather than just getting them from the PersistentClass) // to ensure that entity names/tables are not changed (which would invalidate these test cases). - // Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") - checkDefaultCollectionTableName( Owner.class, "elements", "OWNER_elements" ); + // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated join column. + checkDefaultJoinColumnName( Owner.class, "elements", "Owner_id" ); } protected void checkDefaultCollectionTableName( @@ -354,18 +359,19 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase { // to ensure that entity names/tables are not changed (which would invalidate these test cases). // Matrix has @Entity(name="Mtx"); entity table name defaults to "Mtx"; owner PK column is configured as "mId" - checkDefaultJoinColumnName( Matrix.class, "mvalues", "Mtx_mId" ); + // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated join column. + checkDefaultJoinColumnName( Matrix.class, "mvalues", "Matrix_mId" ); } @Test - @TestForIssue( jiraKey = "HHH-9389") - public void testDefaultJoinColumnOwnerPrimaryTableAndEntityNamesOverride() { + @TestForIssue( jiraKey = "HHH-9387") + public void testDefaultTableNameOwnerPrimaryTableAndEntityNamesOverride() { // NOTE: expected JPA entity names are explicit here (rather than just getting them from the PersistentClass) // to ensure that entity names/tables are not changed (which would invalidate these test cases). - // Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") - checkDefaultJoinColumnName( Owner.class, "elements", "OWNER_id" ); + // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated collection table. + checkDefaultCollectionTableName( Owner.class, "elements", "Owner_elements" ); } protected void checkDefaultJoinColumnName( diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/LegacyNamingCollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/ImprovedNamingCollectionElementTest.java similarity index 75% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/LegacyNamingCollectionElementTest.java rename to hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/ImprovedNamingCollectionElementTest.java index e9b8ddd4d2..3099b6940e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/LegacyNamingCollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/ImprovedNamingCollectionElementTest.java @@ -26,19 +26,21 @@ package org.hibernate.test.annotations.collectionelement; import org.junit.Test; import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.EJB3NamingStrategy; -import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator; +import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator; import org.hibernate.testing.TestForIssue; /** + * Tests @ElementCollection using the "improved" NamingStrategyDelegator which complies + * with JPA spec. + * * @author Gail Badner */ -public class LegacyNamingCollectionElementTest extends CollectionElementTest { +public class ImprovedNamingCollectionElementTest extends DefaultNamingCollectionElementTest { @Override public void configure(Configuration cfg) { super.configure( cfg ); - cfg.setNamingStrategyDelegator( new LegacyNamingStrategyDelegator( EJB3NamingStrategy.INSTANCE ) ); + cfg.setNamingStrategyDelegator( ImprovedNamingStrategyDelegator.DEFAULT_INSTANCE ); } @Test @@ -48,8 +50,7 @@ public class LegacyNamingCollectionElementTest extends CollectionElementTest { // to ensure that entity names/tables are not changed (which would invalidate these test cases). // Matrix has @Entity(name="Mtx"); entity table name defaults to "Mtx"; owner PK column is configured as "mId" - // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated collection table. - checkDefaultCollectionTableName( Matrix.class, "mvalues", "Matrix_mvalues" ); + checkDefaultCollectionTableName( Matrix.class, "mvalues", "Mtx_mvalues" ); } @Test @@ -59,11 +60,9 @@ public class LegacyNamingCollectionElementTest extends CollectionElementTest { // to ensure that entity names/tables are not changed (which would invalidate these test cases). // Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") - // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated collection table. - checkDefaultCollectionTableName( Owner.class, "elements", "Owner_elements" ); + checkDefaultCollectionTableName( Owner.class, "elements", "OWNER_elements" ); } - @Test @TestForIssue( jiraKey = "HHH-9389") public void testDefaultJoinColumnOwnerEntityNameAndPKColumnOverride() { @@ -71,8 +70,7 @@ public class LegacyNamingCollectionElementTest extends CollectionElementTest { // to ensure that entity names/tables are not changed (which would invalidate these test cases). // Matrix has @Entity(name="Mtx"); entity table name defaults to "Mtx"; owner PK column is configured as "mId" - // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated join column. - checkDefaultJoinColumnName( Matrix.class, "mvalues", "Matrix_mId" ); + checkDefaultJoinColumnName( Matrix.class, "mvalues", "Mtx_mId" ); } @Test @@ -82,7 +80,6 @@ public class LegacyNamingCollectionElementTest extends CollectionElementTest { // to ensure that entity names/tables are not changed (which would invalidate these test cases). // Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") - // Legacy behavior used unqualified entity name (instead of JPA entity name) in generated join column. - checkDefaultJoinColumnName( Owner.class, "elements", "Owner_id" ); + checkDefaultJoinColumnName( Owner.class, "elements", "OWNER_id" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/Group.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/Group.java index 174d56d790..03bec71d67 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/Group.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/Group.java @@ -36,7 +36,6 @@ public class Group { } @ManyToMany(cascade = CascadeType.PERSIST) - @JoinTable(joinColumns = {@JoinColumn( name="groupId")}) @OrderBy("expirationDate") @Where(clause = "1=1") @WhereJoinTable(clause = "2=2") diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/GroupWithSet.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/GroupWithSet.java index b6551506fc..e524946650 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/GroupWithSet.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/GroupWithSet.java @@ -36,7 +36,6 @@ public class GroupWithSet { } @ManyToMany(cascade = CascadeType.PERSIST) - @JoinTable(joinColumns = {@JoinColumn( name="groupId")}) @OrderBy("expirationDate") @Where(clause = "1=1") @WhereJoinTable(clause = "2=2") diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyDefaultsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/DefaultNamingManyToManyTest.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyDefaultsTest.java rename to hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/DefaultNamingManyToManyTest.java index d059f9110a..4e310563f6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyDefaultsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/DefaultNamingManyToManyTest.java @@ -38,15 +38,17 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** - * Tests default names for @JoinTable and @JoinColumn for unidirectional and bidirectional - * many-to-many associations. + * Tests names generated for @JoinTable and @JoinColumn for unidirectional and bidirectional + * many-to-many associations when the "default" {@link org.hibernate.cfg.naming.NamingStrategyDelegator} + * is used. The current default does not comply with the JPA spec in some cases. See HHH-9390 + * for more information. * * NOTE: expected primary table names and join columns are explicit here to ensure that * entity names/tables and PK columns are not changed (which would invalidate these test cases). * * @author Gail Badner */ -public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase { +public class DefaultNamingManyToManyTest extends BaseCoreFunctionalTestCase { @Test public void testBidirNoOverrides() { @@ -157,25 +159,6 @@ public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase { ); } - @Test - @TestForIssue( jiraKey = "HHH-9390") - public void testUnidirOwnerPrimaryTableAssocEntityNamePKOverride() { - // City.stolenItems; associated entity: Item - // City has @Entity with no name configured and @Table(name = "tbl_city") - // Item has @Entity(name="ITEM") and no @Table - // PK column for City.id: id (default) - // PK column for Item: iId - // unidirectional - checkDefaultJoinTablAndJoinColumnNames( - City.class, - "stolenItems", - null, - "tbl_city_ITEM", - "City_id", - "stolenItems_iId" - ); - } - @Test @TestForIssue( jiraKey = "HHH-9390") public void testUnidirOwnerEntityNamePrimaryTableOverride() { @@ -185,12 +168,13 @@ public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase { // PK column for Category.id: id (default) // PK column for KnownClient.id: id (default) // unidirectional + // legacy behavior would use the table name in the generated join column. checkDefaultJoinTablAndJoinColumnNames( Category.class, "clients", null, "CATEGORY_TAB_KnownClient", - "CATEGORY_id", + "CATEGORY_TAB_id", "clients_id" ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/LegacyManyToManyDefaultsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ImprovedManyToManyDefaultsTest.java similarity index 80% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/LegacyManyToManyDefaultsTest.java rename to hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ImprovedManyToManyDefaultsTest.java index 24b8b81932..7ba440294c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/LegacyManyToManyDefaultsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ImprovedManyToManyDefaultsTest.java @@ -26,19 +26,22 @@ package org.hibernate.test.annotations.manytomany.defaults; import org.junit.Test; import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.EJB3NamingStrategy; -import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator; -import org.hibernate.testing.FailureExpected; +import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator; import org.hibernate.testing.TestForIssue; /** + * Tests names generated for @JoinTable and @JoinColumn for unidirectional and bidirectional + * many-to-many associations when the "improved" {@link org.hibernate.cfg.naming.NamingStrategyDelegator} + * is used. The "improved" {@link org.hibernate.cfg.naming.NamingStrategyDelegator} complies with the JPA + * spec. + * * @author Gail Badner */ -public class LegacyManyToManyDefaultsTest extends ManyToManyDefaultsTest { +public class ImprovedManyToManyDefaultsTest extends DefaultNamingManyToManyTest { @Override public void configure(Configuration cfg) { super.configure( cfg ); - cfg.setNamingStrategyDelegator( new LegacyNamingStrategyDelegator( EJB3NamingStrategy.INSTANCE ) ); + cfg.setNamingStrategyDelegator( ImprovedNamingStrategyDelegator.DEFAULT_INSTANCE ); } @Test @@ -50,13 +53,12 @@ public class LegacyManyToManyDefaultsTest extends ManyToManyDefaultsTest { // PK column for City.id: id (default) // PK column for Item: iId // unidirectional - // legacy behavior would use the table name in the generated join column. checkDefaultJoinTablAndJoinColumnNames( City.class, "stolenItems", null, "tbl_city_ITEM", - "tbl_city_id", + "City_id", "stolenItems_iId" ); } @@ -70,13 +72,12 @@ public class LegacyManyToManyDefaultsTest extends ManyToManyDefaultsTest { // PK column for Category.id: id (default) // PK column for KnownClient.id: id (default) // unidirectional - // legacy behavior would use the table name in the generated join column. checkDefaultJoinTablAndJoinColumnNames( Category.class, "clients", null, "CATEGORY_TAB_KnownClient", - "CATEGORY_TAB_id", + "CATEGORY_id", "clients_id" ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/MyNamingStrategyDelegator.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/MyNamingStrategyDelegator.java index 27a2eea330..cbe077610a 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/MyNamingStrategyDelegator.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/MyNamingStrategyDelegator.java @@ -24,6 +24,7 @@ package org.hibernate.jpa.test; import org.hibernate.cfg.naming.HbmNamingStrategyDelegate; +import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator; import org.hibernate.cfg.naming.JpaNamingStrategyDelegate; import org.hibernate.cfg.naming.NamingStrategyDelegate; import org.hibernate.cfg.naming.NamingStrategyDelegator; @@ -31,17 +32,12 @@ import org.hibernate.cfg.naming.NamingStrategyDelegator; /** * @author Gail Badner */ -public class MyNamingStrategyDelegator implements NamingStrategyDelegator { - private final NamingStrategyDelegate hbmNamingStrategyDelegate = new HbmNamingStrategyDelegate(); - private final NamingStrategyDelegate nonHbmNamingStrategyDelegate = new MyNonHbmNamingStrategyDelegate(); - - @Override - public NamingStrategyDelegate getNamingStrategyDelegate(boolean isHbm) { - return isHbm ? hbmNamingStrategyDelegate :nonHbmNamingStrategyDelegate; +public class MyNamingStrategyDelegator extends ImprovedNamingStrategyDelegator { + public MyNamingStrategyDelegator() { + super( new HbmNamingStrategyDelegate(), new MyNonHbmNamingStrategyDelegate() ); } - private class MyNonHbmNamingStrategyDelegate extends JpaNamingStrategyDelegate { - + private static class MyNonHbmNamingStrategyDelegate extends JpaNamingStrategyDelegate { @Override public String toPhysicalColumnName(String columnName) { return super.toPhysicalColumnName( "c_" + columnName ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/NamingStrategyDelegatorConfigurationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/NamingStrategyDelegatorConfigurationTest.java index 8abfe53831..bfc3287628 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/NamingStrategyDelegatorConfigurationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/NamingStrategyDelegatorConfigurationTest.java @@ -33,10 +33,10 @@ import org.junit.Test; import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator; import org.hibernate.cfg.naming.NamingStrategyDelegator; import org.hibernate.ejb.AvailableSettings; +import org.hibernate.jpa.test.MyNamingStrategyDelegator; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.test.MyNamingStrategy; -import org.hibernate.jpa.test.MyNamingStrategyDelegator; import org.hibernate.jpa.test.PersistenceUnitInfoAdapter; import org.hibernate.testing.junit4.BaseUnitTestCase;