HHH-9388 HHH-7079 : Default collection table and foreign key names are incorrect in some cases; deprecate NamingStrategy

(cherry picked from commit e5a31caa09)

Conflicts:
	hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java
	hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/MyNamingStrategyDelegator.java
This commit is contained in:
Gail Badner 2014-10-08 03:13:38 -07:00
parent 1cba98022e
commit 52f2c3a002
27 changed files with 353 additions and 397 deletions

View File

@ -80,7 +80,6 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition; import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
import org.hibernate.cfg.annotations.NamedProcedureCallDefinition; import org.hibernate.cfg.annotations.NamedProcedureCallDefinition;
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider; import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
import org.hibernate.cfg.naming.DefaultNamingStrategyDelegator;
import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator; import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator;
import org.hibernate.cfg.naming.NamingStrategyDelegator; import org.hibernate.cfg.naming.NamingStrategyDelegator;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
@ -352,7 +351,7 @@ public class Configuration implements Serializable {
mappedByResolver = new HashMap<String, String>(); mappedByResolver = new HashMap<String, String>();
propertyRefResolver = new HashMap<String, String>(); propertyRefResolver = new HashMap<String, String>();
caches = new ArrayList<CacheHolder>(); caches = new ArrayList<CacheHolder>();
namingStrategyDelegator = DefaultNamingStrategyDelegator.INSTANCE; namingStrategyDelegator = LegacyNamingStrategyDelegator.DEFAULT_INSTANCE;
setEntityResolver( new EJB3DTDEntityResolver() ); setEntityResolver( new EJB3DTDEntityResolver() );
anyMetaDefs = new HashMap<String, AnyMetaDef>(); anyMetaDefs = new HashMap<String, AnyMetaDef>();
propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String, PropertyData>>(); propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String, PropertyData>>();

View File

@ -293,7 +293,7 @@ public class Ejb3Column {
if ( propertyName != null ) { if ( propertyName != null ) {
mappingColumn.setName( mappingColumn.setName(
mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getObjectNameNormalizer().normalizeIdentifierQuoting(
getNamingStrategyDelegate().determineAttributeColumnName( propertyName ) getNamingStrategyDelegate().determineImplicitPropertyColumnName( propertyName )
) )
); );
} }
@ -368,7 +368,8 @@ public class Ejb3Column {
} }
protected void addColumnBinding(SimpleValue value) { 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() ); mappings.addColumnBinding( logicalColumnName, getMappingColumn(), value.getTable() );
} }

View File

@ -455,21 +455,21 @@ public class Ejb3JoinColumn extends Ejb3Column {
if ( mappedBySide ) { if ( mappedBySide ) {
String unquotedMappedbyTable = StringHelper.unquote( mappedByTableName ); String unquotedMappedbyTable = StringHelper.unquote( mappedByTableName );
if ( JPA2ElementCollection ) { if ( JPA2ElementCollection ) {
columnName = getNamingStrategyDelegate().determineElementCollectionForeignKeyColumnName( columnName = getNamingStrategyDelegate().determineImplicitElementCollectionJoinColumnName(
mappedByPropertyName,
mappedByEntityName, mappedByEntityName,
mappedByJpaEntityName, mappedByJpaEntityName,
unquotedMappedbyTable, unquotedMappedbyTable,
unquotedLogicalReferenceColumn unquotedLogicalReferenceColumn,
mappedByPropertyName
); );
} }
else { else {
columnName = getNamingStrategyDelegate().determineEntityAssociationForeignKeyColumnName( columnName = getNamingStrategyDelegate().determineImplicitEntityAssociationJoinColumnName(
mappedByPropertyName,
mappedByEntityName, mappedByEntityName,
mappedByJpaEntityName, mappedByJpaEntityName,
unquotedMappedbyTable, unquotedMappedbyTable,
unquotedLogicalReferenceColumn unquotedLogicalReferenceColumn,
mappedByPropertyName
); );
} }
//one element was quoted so we quote //one element was quoted so we quote
@ -480,12 +480,12 @@ public class Ejb3JoinColumn extends Ejb3Column {
else if ( ownerSide ) { else if ( ownerSide ) {
String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() ); String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() );
String unquotedLogicalTableName = StringHelper.unquote( logicalTableName ); String unquotedLogicalTableName = StringHelper.unquote( logicalTableName );
columnName = getNamingStrategyDelegate().determineEntityAssociationForeignKeyColumnName( columnName = getNamingStrategyDelegate().determineImplicitEntityAssociationJoinColumnName(
getPropertyName(),
referencedEntity.getEntityName(), referencedEntity.getEntityName(),
referencedEntity.getJpaEntityName(), referencedEntity.getJpaEntityName(),
unquotedLogicalTableName, unquotedLogicalTableName,
unquotedLogicalReferenceColumn unquotedLogicalReferenceColumn,
getPropertyName()
); );
//one element was quoted so we quote //one element was quoted so we quote
if ( isRefColumnQuoted || StringHelper.isQuoted( logicalTableName ) ) { 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 //is an intra-entity hierarchy table join so copy the name by default
String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() ); String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() );
String unquotedLogicalTableName = StringHelper.unquote( logicalTableName ); String unquotedLogicalTableName = StringHelper.unquote( logicalTableName );
columnName = getNamingStrategyDelegate().determineJoinKeyColumnName( columnName = getNamingStrategyDelegate().toPhysicalJoinKeyColumnName(
unquotedLogicalReferenceColumn, unquotedLogicalReferenceColumn,
unquotedLogicalTableName unquotedLogicalTableName
); );
@ -538,7 +538,7 @@ public class Ejb3JoinColumn extends Ejb3Column {
final String referencedColumn = nameNormalizer.normalizeIdentifierQuoting( getReferencedColumn() ); final String referencedColumn = nameNormalizer.normalizeIdentifierQuoting( getReferencedColumn() );
final String unquotedLogColName = StringHelper.unquote( logicalColumnName ); final String unquotedLogColName = StringHelper.unquote( logicalColumnName );
final String unquotedRefColumn = StringHelper.unquote( referencedColumn ); final String unquotedRefColumn = StringHelper.unquote( referencedColumn );
String logicalCollectionColumnName = getNamingStrategyDelegate().logicalCollectionColumnName( String logicalCollectionColumnName = getNamingStrategyDelegate().determineLogicalCollectionColumnName(
unquotedLogColName, unquotedLogColName,
getPropertyName(), getPropertyName(),
unquotedRefColumn unquotedRefColumn

View File

@ -889,7 +889,7 @@ public final class HbmBinder {
String physicalTableName; String physicalTableName;
if ( tableNameNode == null ) { if ( tableNameNode == null ) {
logicalTableName = StringHelper.unqualify( model.getEntityName() ); logicalTableName = StringHelper.unqualify( model.getEntityName() );
physicalTableName = getNamingStrategyDelegate( mappings ).determinePrimaryTableLogicalName( physicalTableName = getNamingStrategyDelegate( mappings ).determineImplicitPrimaryTableName(
model.getEntityName(), model.getEntityName(),
model.getJpaEntityName() model.getJpaEntityName()
); );
@ -1081,7 +1081,7 @@ public final class HbmBinder {
column.setTypeIndex( count++ ); column.setTypeIndex( count++ );
bindColumn( columnElement, column, isNullable ); bindColumn( columnElement, column, isNullable );
String columnName = columnElement.attributeValue( "name" ); String columnName = columnElement.attributeValue( "name" );
String logicalColumnName = getNamingStrategyDelegate( mappings ).logicalColumnName( String logicalColumnName = getNamingStrategyDelegate( mappings ).determineLogicalColumnName(
columnName, propertyPath columnName, propertyPath
); );
columnName = getNamingStrategyDelegate( mappings ).toPhysicalColumnName( columnName ); columnName = getNamingStrategyDelegate( mappings ).toPhysicalColumnName( columnName );
@ -1137,7 +1137,7 @@ public final class HbmBinder {
( (ManyToOne) simpleValue ).markAsLogicalOneToOne(); ( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
} }
String columnName = columnAttribute.getValue(); String columnName = columnAttribute.getValue();
String logicalColumnName = getNamingStrategyDelegate( mappings ).logicalColumnName( String logicalColumnName = getNamingStrategyDelegate( mappings ).determineLogicalColumnName(
columnName, propertyPath columnName, propertyPath
); );
columnName = getNamingStrategyDelegate( mappings ).toPhysicalColumnName( columnName ); columnName = getNamingStrategyDelegate( mappings ).toPhysicalColumnName( columnName );
@ -1158,10 +1158,10 @@ public final class HbmBinder {
Column column = new Column(); Column column = new Column();
column.setValue( simpleValue ); column.setValue( simpleValue );
bindColumn( node, column, isNullable ); bindColumn( node, column, isNullable );
String columnName = getNamingStrategyDelegate( mappings ).determineAttributeColumnName( propertyPath ); String columnName = getNamingStrategyDelegate( mappings ).determineImplicitPropertyColumnName( propertyPath );
columnName = quoteIdentifier( columnName, mappings ); columnName = quoteIdentifier( columnName, mappings );
column.setName( columnName ); column.setName( columnName );
String logicalName = getNamingStrategyDelegate( mappings ).logicalColumnName( null, propertyPath ); String logicalName = getNamingStrategyDelegate( mappings ).determineLogicalColumnName( null, propertyPath );
mappings.addColumnBinding( logicalName, column, table ); mappings.addColumnBinding( logicalName, column, table );
/* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a /* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a
* slightly higer level in the stack (to get all the information we need) * 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(); String logicalOwnerTableName = ownerTable.getName();
//FIXME we don't have the associated entity table name here, has to be done in a second pass //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 ) { if ( node.element( "element" ) != null || node.element( "composite-element" ) != null ) {
tableName = getNamingStrategyDelegate( mappings ).determineElementCollectionTableLogicalName( tableName = getNamingStrategyDelegate( mappings ).determineImplicitElementCollectionTableName(
collection.getOwner().getClassName(), collection.getOwner().getClassName(),
collection.getOwner().getEntityName(), collection.getOwner().getJpaEntityName(),
logicalOwnerTableName, logicalOwnerTableName,
path path
); );
} }
else { else {
tableName = getNamingStrategyDelegate( mappings ).determineEntityAssociationJoinTableLogicalName( tableName = getNamingStrategyDelegate( mappings ).determineImplicitEntityAssociationJoinTableName(
collection.getOwner().getEntityName(), collection.getOwner().getClassName(),
collection.getOwner().getJpaEntityName(), collection.getOwner().getJpaEntityName(),
logicalOwnerTableName, logicalOwnerTableName,
null, null,

View File

@ -38,8 +38,9 @@ package org.hibernate.cfg;
* @author Gavin King * @author Gavin King
* @author Emmanuel Bernard * @author Emmanuel Bernard
* *
* @deprecated * @deprecated A {@link org.hibernate.cfg.naming.NamingStrategyDelegator} should be used instead.
*/ */
@Deprecated
public interface NamingStrategy { public interface NamingStrategy {
/** /**
* Return a table name for an entity class * Return a table name for an entity class

View File

@ -563,7 +563,7 @@ public class EntityBinder {
@Override @Override
public String determineImplicitName(NamingStrategyDelegator strategyDelegator) { public String determineImplicitName(NamingStrategyDelegator strategyDelegator) {
return getNamingStrategyDelegate( strategyDelegator ).determinePrimaryTableLogicalName( return getNamingStrategyDelegate( strategyDelegator ).determineImplicitPrimaryTableName(
entityName, entityName,
jpaEntityName jpaEntityName
); );

View File

@ -180,7 +180,7 @@ public class TableBinder {
final NamingStrategyDelegate strategyDelegate = getNamingStrategyDelegate( strategyDelegator ); final NamingStrategyDelegate strategyDelegate = getNamingStrategyDelegate( strategyDelegator );
final String strategyResult; final String strategyResult;
if ( isJPA2ElementCollection ) { if ( isJPA2ElementCollection ) {
strategyResult = strategyDelegate.determineElementCollectionTableLogicalName( strategyResult = strategyDelegate.determineImplicitElementCollectionTableName(
ownerEntity, ownerEntity,
ownerJpaEntity, ownerJpaEntity,
unquotedOwnerTable, unquotedOwnerTable,
@ -188,7 +188,7 @@ public class TableBinder {
); );
} }
else { else {
strategyResult = strategyDelegate.determineEntityAssociationJoinTableLogicalName( strategyResult = strategyDelegate.determineImplicitEntityAssociationJoinTableName(
ownerEntity, ownerEntity,
ownerJpaEntity, ownerJpaEntity,
unquotedOwnerTable, unquotedOwnerTable,
@ -232,7 +232,7 @@ public class TableBinder {
); );
String logicalName; String logicalName;
if ( isJPA2ElementCollection ) { if ( isJPA2ElementCollection ) {
logicalName = strategyDelegate.logicalElementCollectionTableName( logicalName = strategyDelegate.determineLogicalElementCollectionTableName(
name, name,
ownerEntity, ownerEntity,
ownerJpaEntity, ownerJpaEntity,
@ -241,7 +241,7 @@ public class TableBinder {
); );
} }
else { else {
logicalName = strategyDelegate.logicalEntityAssociationJoinTableName( logicalName = strategyDelegate.determineLogicalEntityAssociationJoinTableName(
name, name,
ownerEntity, ownerEntity,
ownerJpaEntity, ownerJpaEntity,

View File

@ -28,55 +28,51 @@ import org.hibernate.internal.util.StringHelper;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate { public class HbmNamingStrategyDelegate extends NamingStrategyDelegateAdapter {
@Override @Override
public String determinePrimaryTableLogicalName(String entityName, String jpaEntityName) { public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName) {
return StringHelper.unqualify( entityName ); return StringHelper.unqualify( entityName );
} }
@Override @Override
public String determineElementCollectionTableLogicalName( public String determineImplicitElementCollectionTableName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String propertyNamePath) { String propertyPath) {
return ownerEntityTable return ownerEntityTable
+ '_' + '_'
+ StringHelper.unqualify( propertyNamePath ); + StringHelper.unqualify( propertyPath );
} }
@Override @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" ); throw new UnsupportedOperationException( "Method not supported for Hibernate-specific mappings" );
} }
@Override @Override
public String determineEntityAssociationJoinTableLogicalName( public String determineImplicitEntityAssociationJoinTableName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String associatedEntityName, String associatedEntityName,
String associatedJpaEntityName, String associatedJpaEntityName,
String associatedEntityTable, String associatedEntityTable,
String propertyNamePath) { String propertyPath) {
return ownerEntityTable return ownerEntityTable
+ '_' + '_'
+ StringHelper.unqualify( propertyNamePath ); + StringHelper.unqualify( propertyPath );
} }
@Override @Override
public String determineEntityAssociationForeignKeyColumnName( public String determineImplicitEntityAssociationJoinColumnName(
String propertyName, String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String propertyPath) {
String propertyEntityName,
String propertyJpaEntityName,
String propertyTableName,
String referencedColumnName) {
throw new UnsupportedOperationException( "Method not supported for Hibernate-specific mappings" ); throw new UnsupportedOperationException( "Method not supported for Hibernate-specific mappings" );
} }
@Override @Override
public String logicalElementCollectionTableName( public String determineLogicalElementCollectionTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
@ -86,7 +82,7 @@ public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
return tableName; return tableName;
} }
else { else {
return determineElementCollectionTableLogicalName( return determineImplicitElementCollectionTableName(
ownerEntityName, ownerEntityName,
ownerJpaEntityName, ownerJpaEntityName,
ownerEntityTable, ownerEntityTable,
@ -96,7 +92,7 @@ public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
} }
@Override @Override
public String logicalEntityAssociationJoinTableName( public String determineLogicalEntityAssociationJoinTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
@ -109,7 +105,7 @@ public class HbmNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
return tableName; return tableName;
} }
else { else {
return determineEntityAssociationJoinTableLogicalName( return determineImplicitEntityAssociationJoinTableName(
ownerEntityName, ownerEntityName,
ownerJpaEntityName, ownerJpaEntityName,
ownerEntityTable, ownerEntityTable,

View File

@ -28,15 +28,24 @@ import java.io.Serializable;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class DefaultNamingStrategyDelegator implements NamingStrategyDelegator, Serializable { public class ImprovedNamingStrategyDelegator implements NamingStrategyDelegator, Serializable {
public static final DefaultNamingStrategyDelegator INSTANCE = new DefaultNamingStrategyDelegator(); public static final NamingStrategyDelegator DEFAULT_INSTANCE = new ImprovedNamingStrategyDelegator();
private final NamingStrategyDelegate hbmNamingStrategyDelegate; private final NamingStrategyDelegate hbmNamingStrategyDelegate;
private final NamingStrategyDelegate jpaNamingStrategyDelegate; private final NamingStrategyDelegate jpaNamingStrategyDelegate;
private DefaultNamingStrategyDelegator() { private ImprovedNamingStrategyDelegator() {
this.hbmNamingStrategyDelegate = new HbmNamingStrategyDelegate(); this(
this.jpaNamingStrategyDelegate = new JpaNamingStrategyDelegate(); new HbmNamingStrategyDelegate(),
new JpaNamingStrategyDelegate()
);
}
protected ImprovedNamingStrategyDelegator(
NamingStrategyDelegate hbmNamingStrategyDelegate,
NamingStrategyDelegate jpaNamingStrategyDelegate) {
this.hbmNamingStrategyDelegate = hbmNamingStrategyDelegate;
this.jpaNamingStrategyDelegate = jpaNamingStrategyDelegate;
} }
@Override @Override

View File

@ -29,19 +29,19 @@ import org.hibernate.internal.util.StringHelper;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate { public class JpaNamingStrategyDelegate extends NamingStrategyDelegateAdapter {
@Override @Override
public String determinePrimaryTableLogicalName(String entityName, String jpaEntityName) { public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName) {
return StringHelper.unqualify( determineEntityNameToUse( entityName, jpaEntityName ) ); return StringHelper.unqualify( determineEntityNameToUse( entityName, jpaEntityName ) );
} }
@Override @Override
public String determineElementCollectionTableLogicalName( public String determineImplicitElementCollectionTableName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String propertyNamePath) { String propertyPath) {
// JPA states we should use the following as default: // JPA states we should use the following as default:
// "The concatenation of the name of the containing entity and the name of the // "The concatenation of the name of the containing entity and the name of the
// collection attribute, separated by an underscore. // collection attribute, separated by an underscore.
@ -50,33 +50,29 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
// otherwise: {OWNER ENTITY NAME}_{COLLECTION ATTRIBUTE NAME} // otherwise: {OWNER ENTITY NAME}_{COLLECTION ATTRIBUTE NAME}
return determineEntityNameToUse( ownerEntityName, ownerJpaEntityName ) return determineEntityNameToUse( ownerEntityName, ownerJpaEntityName )
+ '_' + '_'
+ StringHelper.unqualify( propertyNamePath ); + StringHelper.unqualify( propertyPath );
} }
@Override @Override
public String determineElementCollectionForeignKeyColumnName( public String determineImplicitElementCollectionJoinColumnName(
String propertyName, String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String referencedColumnName, String propertyPath) {
String propertyEntityName,
String propertyJpaEntityName,
String propertyTableName,
String referencedColumnName) {
// JPA states we should use the following as default: // JPA states we should use the following as default:
// "The concatenation of the following: the name of the entity; "_"; the name of the // "The concatenation of the following: the name of the entity; "_"; the name of the
// referenced primary key column" // referenced primary key column"
return determineEntityNameToUse( propertyEntityName, propertyJpaEntityName ) return determineEntityNameToUse( ownerEntityName, ownerJpaEntityName )
+ '_' + '_'
+ referencedColumnName; + referencedColumnName;
} }
@Override @Override
public String determineEntityAssociationJoinTableLogicalName( public String determineImplicitEntityAssociationJoinTableName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String associatedEntityName, String associatedEntityName,
String associatedJpaEntityName, String associatedJpaEntityName,
String associatedEntityTable, String associatedEntityTable,
String propertyNamePath) { String propertyPath) {
// JPA states we should use the following as default: // JPA states we should use the following as default:
// "The concatenated names of the two associated primary entity tables (owning side // "The concatenated names of the two associated primary entity tables (owning side
// first), separated by an underscore." // first), separated by an underscore."
@ -89,12 +85,8 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
} }
@Override @Override
public String determineEntityAssociationForeignKeyColumnName( public String determineImplicitEntityAssociationJoinColumnName(
String referencingPropertyName, String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String referencingPropertyName) {
String propertyEntityName,
String propertyJpaEntityName,
String propertyTableName,
String referencedColumnName) {
// JPA states we should use the following as default: // JPA states we should use the following as default:
// "The concatenation of the following: the name of the referencing relationship // "The concatenation of the following: the name of the referencing relationship
// property or field of the referencing entity or embeddable class; "_"; the name // property or field of the referencing entity or embeddable class; "_"; the name
@ -125,7 +117,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
} }
@Override @Override
public String logicalElementCollectionTableName( public String determineLogicalElementCollectionTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
@ -135,7 +127,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
return tableName; return tableName;
} }
else { else {
return determineElementCollectionTableLogicalName( return determineImplicitElementCollectionTableName(
ownerEntityName, ownerEntityName,
ownerJpaEntityName, ownerJpaEntityName,
ownerEntityTable, ownerEntityTable,
@ -145,7 +137,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
} }
@Override @Override
public String logicalEntityAssociationJoinTableName( public String determineLogicalEntityAssociationJoinTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
@ -158,7 +150,7 @@ public class JpaNamingStrategyDelegate extends AbstractNamingStrategyDelegate {
return tableName; return tableName;
} }
else { else {
return determineEntityAssociationJoinTableLogicalName( return determineImplicitEntityAssociationJoinTableName(
ownerEntityName, ownerEntityName,
ownerJpaEntityName, ownerJpaEntityName,
ownerEntityTable, ownerEntityTable,

View File

@ -26,64 +26,67 @@ package org.hibernate.cfg.naming;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class LegacyHbmNamingStrategyDelegate extends AbstractLegacyNamingStrategyDelegate { @Deprecated
public class LegacyHbmNamingStrategyDelegate extends LegacyNamingStrategyDelegateAdapter {
public LegacyHbmNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { public LegacyHbmNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) {
super( context ); super( context );
} }
@Override @Override
public String determineElementCollectionTableLogicalName( public String determineImplicitPrimaryTableName(String entityName, String jpaEntityName) {
return getNamingStrategy().classToTableName( entityName );
}
@Override
public String determineImplicitElementCollectionTableName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String propertyNamePath) { String propertyPath) {
return getNamingStrategy().collectionTableName( return getNamingStrategy().collectionTableName(
ownerEntityName, ownerEntityName,
ownerEntityTable, ownerEntityTable,
null, null,
null, null,
propertyNamePath propertyPath
); );
} }
@Override @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( return getNamingStrategy().foreignKeyColumnName(
propertyName, propertyPath,
propertyEntityName, ownerEntityName,
propertyTableName, ownerEntityTable,
referencedColumnName referencedColumnName
); );
} }
@Override @Override
public String determineEntityAssociationJoinTableLogicalName( public String determineImplicitEntityAssociationJoinTableName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String associatedEntityName, String associatedEntityName,
String associatedJpaEntityName, String associatedJpaEntityName,
String associatedEntityTable, String associatedEntityTable,
String propertyNamePath) { String propertyPath) {
return getNamingStrategy().collectionTableName( return getNamingStrategy().collectionTableName(
ownerEntityName, ownerEntityName,
ownerEntityTable, ownerEntityTable,
associatedEntityName, associatedEntityName,
associatedEntityTable, associatedEntityTable,
propertyNamePath propertyPath
); );
} }
@Override @Override
public String determineEntityAssociationForeignKeyColumnName( public String determineImplicitEntityAssociationJoinColumnName(
String propertyName, String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String propertyPath) {
String propertyEntityName,
String propertyJpaEntityName,
String propertyTableName,
String referencedColumnName) {
return getNamingStrategy().foreignKeyColumnName( return getNamingStrategy().foreignKeyColumnName(
propertyName, propertyPath,
propertyEntityName, propertyEntityName,
propertyTableName, propertyTableName,
referencedColumnName referencedColumnName
@ -91,7 +94,7 @@ public class LegacyHbmNamingStrategyDelegate extends AbstractLegacyNamingStrateg
} }
@Override @Override
public String logicalElementCollectionTableName( public String determineLogicalElementCollectionTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
@ -106,7 +109,7 @@ public class LegacyHbmNamingStrategyDelegate extends AbstractLegacyNamingStrateg
} }
@Override @Override
public String logicalEntityAssociationJoinTableName( public String determineLogicalEntityAssociationJoinTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,

View File

@ -28,69 +28,68 @@ import org.hibernate.internal.util.StringHelper;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class LegacyStandardNamingStrategyDelegate extends AbstractLegacyNamingStrategyDelegate { @Deprecated
public class LegacyJpaNamingStrategyDelegate extends LegacyNamingStrategyDelegateAdapter {
LegacyStandardNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { LegacyJpaNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) {
super( context ); super( context );
} }
@Override @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 ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String propertyNamePath) { String propertyPath) {
return getNamingStrategy().collectionTableName( return getNamingStrategy().collectionTableName(
ownerEntityName, ownerEntityName,
StringHelper.unqualifyEntityName( ownerEntityName ), StringHelper.unqualifyEntityName( ownerEntityName ),
null, null,
null, null,
propertyNamePath propertyPath
); );
} }
@Override @Override
public String determineElementCollectionForeignKeyColumnName( public String determineImplicitElementCollectionJoinColumnName(
String propertyName, String ownerEntityName, String ownerJpaEntityName, String ownerEntityTable, String referencedColumnName, String propertyPath) {
String propertyEntityName,
String propertyJpaEntityName,
String propertyTableName,
String referencedColumnName) {
return getNamingStrategy().foreignKeyColumnName( return getNamingStrategy().foreignKeyColumnName(
propertyName, propertyPath,
propertyEntityName, ownerEntityName,
StringHelper.unqualifyEntityName( propertyEntityName ), StringHelper.unqualifyEntityName( ownerEntityName ),
referencedColumnName referencedColumnName
); );
} }
@Override @Override
public String determineEntityAssociationJoinTableLogicalName( public String determineImplicitEntityAssociationJoinTableName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String associatedEntityName, String associatedEntityName,
String associatedJpaEntityName, String associatedJpaEntityName,
String associatedEntityTable, String associatedEntityTable,
String propertyNamePath) { String propertyPath) {
return getNamingStrategy().collectionTableName( return getNamingStrategy().collectionTableName(
ownerEntityName, ownerEntityName,
ownerEntityTable, ownerEntityTable,
associatedEntityName, associatedEntityName,
associatedEntityTable, associatedEntityTable,
propertyNamePath propertyPath
); );
} }
@Override @Override
public String determineEntityAssociationForeignKeyColumnName( public String determineImplicitEntityAssociationJoinColumnName(
String propertyName, String propertyEntityName, String propertyJpaEntityName, String propertyTableName, String referencedColumnName, String propertyPath) {
String propertyEntityName,
String propertyJpaEntityName,
String propertyTableName,
String referencedColumnName) {
return getNamingStrategy().foreignKeyColumnName( return getNamingStrategy().foreignKeyColumnName(
propertyName, propertyPath,
propertyEntityName, propertyEntityName,
propertyTableName, propertyTableName,
referencedColumnName referencedColumnName
@ -98,7 +97,7 @@ public class LegacyStandardNamingStrategyDelegate extends AbstractLegacyNamingSt
} }
@Override @Override
public String logicalElementCollectionTableName( public String determineLogicalElementCollectionTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
@ -113,7 +112,7 @@ public class LegacyStandardNamingStrategyDelegate extends AbstractLegacyNamingSt
} }
@Override @Override
public String logicalEntityAssociationJoinTableName( public String determineLogicalEntityAssociationJoinTableName(
String tableName, String tableName,
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,

View File

@ -28,6 +28,7 @@ import org.hibernate.cfg.NamingStrategy;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@Deprecated
public interface LegacyNamingStrategyDelegate extends NamingStrategyDelegate { public interface LegacyNamingStrategyDelegate extends NamingStrategyDelegate {
public static interface LegacyNamingStrategyDelegateContext { public static interface LegacyNamingStrategyDelegateContext {
public NamingStrategy getNamingStrategy(); public NamingStrategy getNamingStrategy();

View File

@ -30,10 +30,11 @@ import org.hibernate.cfg.NamingStrategy;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public abstract class AbstractLegacyNamingStrategyDelegate implements NamingStrategyDelegate, Serializable { @Deprecated
public abstract class LegacyNamingStrategyDelegateAdapter implements NamingStrategyDelegate, Serializable {
private final LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context; private final LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context;
public AbstractLegacyNamingStrategyDelegate(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) { public LegacyNamingStrategyDelegateAdapter(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) {
this.context = context; this.context = context;
} }
@ -41,12 +42,6 @@ public abstract class AbstractLegacyNamingStrategyDelegate implements NamingStra
return context.getNamingStrategy(); 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 @Override
public String toPhysicalTableName(String tableName) { public String toPhysicalTableName(String tableName) {
return getNamingStrategy().tableName( tableName ); return getNamingStrategy().tableName( tableName );
@ -58,22 +53,22 @@ public abstract class AbstractLegacyNamingStrategyDelegate implements NamingStra
} }
@Override @Override
public String determineAttributeColumnName(String propertyName) { public String determineImplicitPropertyColumnName(String propertyPath) {
return getNamingStrategy().propertyToColumnName( propertyName ); return getNamingStrategy().propertyToColumnName( propertyPath );
} }
@Override @Override
public String determineJoinKeyColumnName(String joinedColumn, String joinedTable) { public String toPhysicalJoinKeyColumnName(String joinedColumn, String joinedTable) {
return getNamingStrategy().joinKeyColumnName( joinedColumn, joinedTable ); return getNamingStrategy().joinKeyColumnName( joinedColumn, joinedTable );
} }
@Override @Override
public String logicalColumnName(String columnName, String propertyName) { public String determineLogicalColumnName(String columnName, String propertyName) {
return getNamingStrategy().logicalColumnName( columnName, propertyName ); return getNamingStrategy().logicalColumnName( columnName, propertyName );
} }
@Override @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 ); return getNamingStrategy().logicalCollectionColumnName( columnName, propertyName, referencedColumn );
} }
} }

View File

@ -31,7 +31,6 @@ import org.hibernate.cfg.NamingStrategy;
import static org.hibernate.cfg.naming.LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext; import static org.hibernate.cfg.naming.LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext;
/** /**
*
* @deprecated Needed as a transitory implementation until the deprecated NamingStrategy contract * @deprecated Needed as a transitory implementation until the deprecated NamingStrategy contract
* can be removed. * can be removed.
* *
@ -40,18 +39,20 @@ import static org.hibernate.cfg.naming.LegacyNamingStrategyDelegate.LegacyNaming
@Deprecated @Deprecated
public class LegacyNamingStrategyDelegator public class LegacyNamingStrategyDelegator
implements NamingStrategyDelegator, LegacyNamingStrategyDelegateContext, Serializable { implements NamingStrategyDelegator, LegacyNamingStrategyDelegateContext, Serializable {
public static final NamingStrategyDelegator DEFAULT_INSTANCE = new LegacyNamingStrategyDelegator();
private final NamingStrategy namingStrategy; private final NamingStrategy namingStrategy;
private final NamingStrategyDelegate hbmNamingStrategyDelegate; private final NamingStrategyDelegate hbmNamingStrategyDelegate;
private final NamingStrategyDelegate jpaNamingStrategyDelegate; private final NamingStrategyDelegate jpaNamingStrategyDelegate;
public LegacyNamingStrategyDelegator() { private LegacyNamingStrategyDelegator() {
this( EJB3NamingStrategy.INSTANCE ); this( EJB3NamingStrategy.INSTANCE );
} }
public LegacyNamingStrategyDelegator(NamingStrategy namingStrategy) { public LegacyNamingStrategyDelegator(NamingStrategy namingStrategy) {
this.namingStrategy = namingStrategy; this.namingStrategy = namingStrategy;
this.hbmNamingStrategyDelegate = new LegacyHbmNamingStrategyDelegate( this ); this.hbmNamingStrategyDelegate = new LegacyHbmNamingStrategyDelegate( this );
this.jpaNamingStrategyDelegate = new LegacyStandardNamingStrategyDelegate( this ); this.jpaNamingStrategyDelegate = new LegacyJpaNamingStrategyDelegate( this );
} }
public NamingStrategy getNamingStrategy() { public NamingStrategy getNamingStrategy() {

View File

@ -24,13 +24,137 @@
package org.hibernate.cfg.naming; package org.hibernate.cfg.naming;
/** /**
* A
* @author Gail Badner * @author Gail Badner
*/ */
public interface NamingStrategyDelegate { 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 * Alter the table name given in the mapping document
@ -46,57 +170,4 @@ public interface NamingStrategyDelegate {
*/ */
public String toPhysicalColumnName(String columnName); 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);
} }

View File

@ -28,9 +28,16 @@ import java.io.Serializable;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
/** /**
* An "adapter" for {@link NamingStrategyDelegate} implementations to extend.
*
* @author Gail Badner * @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 @Override
public String toPhysicalTableName(String tableName) { public String toPhysicalTableName(String tableName) {
@ -43,22 +50,17 @@ public abstract class AbstractNamingStrategyDelegate implements NamingStrategyDe
} }
@Override @Override
public String determineAttributeColumnName(String propertyName) { public String toPhysicalJoinKeyColumnName(String joinedColumn, String joinedTable) {
return StringHelper.unqualify( propertyName );
}
@Override
public String determineJoinKeyColumnName(String joinedColumn, String joinedTable) {
return toPhysicalColumnName( joinedColumn ); return toPhysicalColumnName( joinedColumn );
} }
@Override @Override
public String logicalColumnName(String columnName, String propertyName) { public String determineLogicalColumnName(String columnName, String propertyName) {
return StringHelper.isNotEmpty( columnName ) ? columnName : StringHelper.unqualify( propertyName ); return StringHelper.isNotEmpty( columnName ) ? columnName : StringHelper.unqualify( propertyName );
} }
@Override @Override
public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { public String determineLogicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) {
return StringHelper.isNotEmpty( columnName ) ? return StringHelper.isNotEmpty( columnName ) ?
columnName : columnName :
StringHelper.unqualify( propertyName ) + "_" + referencedColumn; StringHelper.unqualify( propertyName ) + "_" + referencedColumn;

View File

@ -23,12 +23,13 @@
*/ */
package org.hibernate.cfg.naming; 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 * @author Gail Badner
*
* @see org.hibernate.cfg.naming.NamingStrategyDelegate
*/ */
public interface NamingStrategyDelegator { public interface NamingStrategyDelegator {

View File

@ -26,24 +26,20 @@ package org.hibernate.test.annotations.collectionelement;
import org.junit.Test; import org.junit.Test;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.EJB3NamingStrategy; import org.hibernate.cfg.naming.HbmNamingStrategyDelegate;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator;
import org.hibernate.cfg.naming.AbstractLegacyNamingStrategyDelegate; import org.hibernate.cfg.naming.JpaNamingStrategyDelegate;
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.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class CustomNamingCollectionElementTest extends CollectionElementTest { public class CustomImprovedNamingCollectionElementTest extends ImprovedNamingCollectionElementTest {
@Override @Override
public void configure(Configuration cfg) { public void configure(Configuration cfg) {
super.configure( cfg ); super.configure( cfg );
cfg.setNamingStrategyDelegator( new MyLegacyNamingStrategyDelegator() ); cfg.setNamingStrategyDelegator( new MyImprovedNamingStrategyDelegator() );
} }
@Test @Test
@ -114,131 +110,38 @@ public class CustomNamingCollectionElementTest extends CollectionElementTest {
checkDefaultCollectionTableName( Boy.class, "hatedNames", "tbl_Boys_hatedNames" ); checkDefaultCollectionTableName( Boy.class, "hatedNames", "tbl_Boys_hatedNames" );
} }
static class MyLegacyNamingStrategyDelegator extends LegacyNamingStrategyDelegator { static class MyImprovedNamingStrategyDelegator extends ImprovedNamingStrategyDelegator {
private final NamingStrategyDelegate hbmNamingStrategyDelegate = new LegacyHbmNamingStrategyDelegate( this ); public MyImprovedNamingStrategyDelegator() {
private final NamingStrategyDelegate nonHbmNamingStrategyDelegate = new MyNonHbmNamingStrategyDelegator( this ); super( new HbmNamingStrategyDelegate(), new MyNonHbmNamingStrategyDelegate() );
@Override
public NamingStrategyDelegate getNamingStrategyDelegate(boolean isHbm) {
return isHbm ? hbmNamingStrategyDelegate : nonHbmNamingStrategyDelegate;
} }
@Override private static class MyNonHbmNamingStrategyDelegate extends JpaNamingStrategyDelegate {
public NamingStrategy getNamingStrategy() {
return EJB3NamingStrategy.INSTANCE;
}
private class MyNonHbmNamingStrategyDelegator extends AbstractLegacyNamingStrategyDelegate {
MyNonHbmNamingStrategyDelegator(LegacyNamingStrategyDelegate.LegacyNamingStrategyDelegateContext context) {
super( context );
}
@Override @Override
public String toPhysicalTableName(String tableName) { public String determineImplicitElementCollectionTableName(
return getNamingStrategy().tableName( tableName );
}
@Override
public String toPhysicalColumnName(String columnName) {
return getNamingStrategy().columnName( columnName );
}
@Override
public String determineElementCollectionTableLogicalName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String propertyNamePath) { String propertyPath) {
return getNamingStrategy().collectionTableName( // This impl uses the owner entity table name instead of the JPA entity name when
ownerEntityName, // generating the implicit name.
ownerEntityTable, int loc = propertyPath.lastIndexOf(".");
null, final String unqualifiedPropertyName = loc < 0 ? propertyPath : propertyPath.substring( loc + 1 );
null, return ownerEntityTable
propertyNamePath + '_'
); + unqualifiedPropertyName;
} }
@Override @Override
public String determineElementCollectionForeignKeyColumnName( public String determineImplicitElementCollectionJoinColumnName(
String propertyName,
String propertyEntityName,
String propertyJpaEntityName,
String propertyTableName,
String referencedColumnName) {
return getNamingStrategy().foreignKeyColumnName(
propertyName,
propertyEntityName,
propertyTableName,
referencedColumnName
);
}
@Override
public String determineEntityAssociationJoinTableLogicalName(
String ownerEntityName, String ownerEntityName,
String ownerJpaEntityName, String ownerJpaEntityName,
String ownerEntityTable, String ownerEntityTable,
String associatedEntityName, String referencedColumnName,
String associatedJpaEntityName, String propertyPath) {
String associatedEntityTable, return ownerEntityTable
String propertyNamePath) { + '_'
return getNamingStrategy().collectionTableName( + referencedColumnName;
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
);
} }
} }
} }
} }

View File

@ -47,11 +47,16 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; 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 Emmanuel Bernard
* @author Hardy Ferentschik * @author Hardy Ferentschik
* @author Gail Badner
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class CollectionElementTest extends BaseCoreFunctionalTestCase { public class DefaultNamingCollectionElementTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testSimpleElement() throws Exception { public void testSimpleElement() throws Exception {
assertEquals( assertEquals(
@ -274,7 +279,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase {
assertTrue( "Could not find " + columnName, hasDefault ); assertTrue( "Could not find " + columnName, hasDefault );
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-9387") @TestForIssue( jiraKey = "HHH-9387")
public void testDefaultTableNameNoOverrides() { 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). // 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" // 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 @Test
@TestForIssue( jiraKey = "HHH-9387") @TestForIssue( jiraKey = "HHH-9389")
public void testDefaultTableNameOwnerPrimaryTableAndEntityNamesOverride() { public void testDefaultJoinColumnOwnerPrimaryTableAndEntityNamesOverride() {
// NOTE: expected JPA entity names are explicit here (rather than just getting them from the PersistentClass) // 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). // to ensure that entity names/tables are not changed (which would invalidate these test cases).
// Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") // 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( 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). // 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" // 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 @Test
@TestForIssue( jiraKey = "HHH-9389") @TestForIssue( jiraKey = "HHH-9387")
public void testDefaultJoinColumnOwnerPrimaryTableAndEntityNamesOverride() { public void testDefaultTableNameOwnerPrimaryTableAndEntityNamesOverride() {
// NOTE: expected JPA entity names are explicit here (rather than just getting them from the PersistentClass) // 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). // to ensure that entity names/tables are not changed (which would invalidate these test cases).
// Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") // 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( protected void checkDefaultJoinColumnName(

View File

@ -26,19 +26,21 @@ package org.hibernate.test.annotations.collectionelement;
import org.junit.Test; import org.junit.Test;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.EJB3NamingStrategy; import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator;
import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
/** /**
* Tests @ElementCollection using the "improved" NamingStrategyDelegator which complies
* with JPA spec.
*
* @author Gail Badner * @author Gail Badner
*/ */
public class LegacyNamingCollectionElementTest extends CollectionElementTest { public class ImprovedNamingCollectionElementTest extends DefaultNamingCollectionElementTest {
@Override @Override
public void configure(Configuration cfg) { public void configure(Configuration cfg) {
super.configure( cfg ); super.configure( cfg );
cfg.setNamingStrategyDelegator( new LegacyNamingStrategyDelegator( EJB3NamingStrategy.INSTANCE ) ); cfg.setNamingStrategyDelegator( ImprovedNamingStrategyDelegator.DEFAULT_INSTANCE );
} }
@Test @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). // 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" // 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", "Mtx_mvalues" );
checkDefaultCollectionTableName( Matrix.class, "mvalues", "Matrix_mvalues" );
} }
@Test @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). // to ensure that entity names/tables are not changed (which would invalidate these test cases).
// Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") // 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 @Test
@TestForIssue( jiraKey = "HHH-9389") @TestForIssue( jiraKey = "HHH-9389")
public void testDefaultJoinColumnOwnerEntityNameAndPKColumnOverride() { 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). // 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" // 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", "Mtx_mId" );
checkDefaultJoinColumnName( Matrix.class, "mvalues", "Matrix_mId" );
} }
@Test @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). // to ensure that entity names/tables are not changed (which would invalidate these test cases).
// Owner has @Entity( name="OWNER") @Table( name="OWNER_TABLE") // 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" );
} }
} }

View File

@ -36,7 +36,6 @@ public class Group {
} }
@ManyToMany(cascade = CascadeType.PERSIST) @ManyToMany(cascade = CascadeType.PERSIST)
@JoinTable(joinColumns = {@JoinColumn( name="groupId")})
@OrderBy("expirationDate") @OrderBy("expirationDate")
@Where(clause = "1=1") @Where(clause = "1=1")
@WhereJoinTable(clause = "2=2") @WhereJoinTable(clause = "2=2")

View File

@ -36,7 +36,6 @@ public class GroupWithSet {
} }
@ManyToMany(cascade = CascadeType.PERSIST) @ManyToMany(cascade = CascadeType.PERSIST)
@JoinTable(joinColumns = {@JoinColumn( name="groupId")})
@OrderBy("expirationDate") @OrderBy("expirationDate")
@Where(clause = "1=1") @Where(clause = "1=1")
@WhereJoinTable(clause = "2=2") @WhereJoinTable(clause = "2=2")

View File

@ -38,15 +38,17 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Tests default names for @JoinTable and @JoinColumn for unidirectional and bidirectional * Tests names generated for @JoinTable and @JoinColumn for unidirectional and bidirectional
* many-to-many associations. * 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 * 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). * entity names/tables and PK columns are not changed (which would invalidate these test cases).
* *
* @author Gail Badner * @author Gail Badner
*/ */
public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase { public class DefaultNamingManyToManyTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testBidirNoOverrides() { 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 @Test
@TestForIssue( jiraKey = "HHH-9390") @TestForIssue( jiraKey = "HHH-9390")
public void testUnidirOwnerEntityNamePrimaryTableOverride() { public void testUnidirOwnerEntityNamePrimaryTableOverride() {
@ -185,12 +168,13 @@ public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase {
// PK column for Category.id: id (default) // PK column for Category.id: id (default)
// PK column for KnownClient.id: id (default) // PK column for KnownClient.id: id (default)
// unidirectional // unidirectional
// legacy behavior would use the table name in the generated join column.
checkDefaultJoinTablAndJoinColumnNames( checkDefaultJoinTablAndJoinColumnNames(
Category.class, Category.class,
"clients", "clients",
null, null,
"CATEGORY_TAB_KnownClient", "CATEGORY_TAB_KnownClient",
"CATEGORY_id", "CATEGORY_TAB_id",
"clients_id" "clients_id"
); );

View File

@ -26,19 +26,22 @@ package org.hibernate.test.annotations.manytomany.defaults;
import org.junit.Test; import org.junit.Test;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.EJB3NamingStrategy; import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator;
import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue; 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 * @author Gail Badner
*/ */
public class LegacyManyToManyDefaultsTest extends ManyToManyDefaultsTest { public class ImprovedManyToManyDefaultsTest extends DefaultNamingManyToManyTest {
@Override @Override
public void configure(Configuration cfg) { public void configure(Configuration cfg) {
super.configure( cfg ); super.configure( cfg );
cfg.setNamingStrategyDelegator( new LegacyNamingStrategyDelegator( EJB3NamingStrategy.INSTANCE ) ); cfg.setNamingStrategyDelegator( ImprovedNamingStrategyDelegator.DEFAULT_INSTANCE );
} }
@Test @Test
@ -50,13 +53,12 @@ public class LegacyManyToManyDefaultsTest extends ManyToManyDefaultsTest {
// PK column for City.id: id (default) // PK column for City.id: id (default)
// PK column for Item: iId // PK column for Item: iId
// unidirectional // unidirectional
// legacy behavior would use the table name in the generated join column.
checkDefaultJoinTablAndJoinColumnNames( checkDefaultJoinTablAndJoinColumnNames(
City.class, City.class,
"stolenItems", "stolenItems",
null, null,
"tbl_city_ITEM", "tbl_city_ITEM",
"tbl_city_id", "City_id",
"stolenItems_iId" "stolenItems_iId"
); );
} }
@ -70,13 +72,12 @@ public class LegacyManyToManyDefaultsTest extends ManyToManyDefaultsTest {
// PK column for Category.id: id (default) // PK column for Category.id: id (default)
// PK column for KnownClient.id: id (default) // PK column for KnownClient.id: id (default)
// unidirectional // unidirectional
// legacy behavior would use the table name in the generated join column.
checkDefaultJoinTablAndJoinColumnNames( checkDefaultJoinTablAndJoinColumnNames(
Category.class, Category.class,
"clients", "clients",
null, null,
"CATEGORY_TAB_KnownClient", "CATEGORY_TAB_KnownClient",
"CATEGORY_TAB_id", "CATEGORY_id",
"clients_id" "clients_id"
); );

View File

@ -24,6 +24,7 @@
package org.hibernate.jpa.test; package org.hibernate.jpa.test;
import org.hibernate.cfg.naming.HbmNamingStrategyDelegate; import org.hibernate.cfg.naming.HbmNamingStrategyDelegate;
import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator;
import org.hibernate.cfg.naming.JpaNamingStrategyDelegate; import org.hibernate.cfg.naming.JpaNamingStrategyDelegate;
import org.hibernate.cfg.naming.NamingStrategyDelegate; import org.hibernate.cfg.naming.NamingStrategyDelegate;
import org.hibernate.cfg.naming.NamingStrategyDelegator; import org.hibernate.cfg.naming.NamingStrategyDelegator;
@ -31,17 +32,12 @@ import org.hibernate.cfg.naming.NamingStrategyDelegator;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class MyNamingStrategyDelegator implements NamingStrategyDelegator { public class MyNamingStrategyDelegator extends ImprovedNamingStrategyDelegator {
private final NamingStrategyDelegate hbmNamingStrategyDelegate = new HbmNamingStrategyDelegate(); public MyNamingStrategyDelegator() {
private final NamingStrategyDelegate nonHbmNamingStrategyDelegate = new MyNonHbmNamingStrategyDelegate(); super( new HbmNamingStrategyDelegate(), new MyNonHbmNamingStrategyDelegate() );
@Override
public NamingStrategyDelegate getNamingStrategyDelegate(boolean isHbm) {
return isHbm ? hbmNamingStrategyDelegate :nonHbmNamingStrategyDelegate;
} }
private class MyNonHbmNamingStrategyDelegate extends JpaNamingStrategyDelegate { private static class MyNonHbmNamingStrategyDelegate extends JpaNamingStrategyDelegate {
@Override @Override
public String toPhysicalColumnName(String columnName) { public String toPhysicalColumnName(String columnName) {
return super.toPhysicalColumnName( "c_" + columnName ); return super.toPhysicalColumnName( "c_" + columnName );

View File

@ -33,10 +33,10 @@ import org.junit.Test;
import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator; import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator;
import org.hibernate.cfg.naming.NamingStrategyDelegator; import org.hibernate.cfg.naming.NamingStrategyDelegator;
import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.AvailableSettings;
import org.hibernate.jpa.test.MyNamingStrategyDelegator;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.test.MyNamingStrategy; import org.hibernate.jpa.test.MyNamingStrategy;
import org.hibernate.jpa.test.MyNamingStrategyDelegator;
import org.hibernate.jpa.test.PersistenceUnitInfoAdapter; import org.hibernate.jpa.test.PersistenceUnitInfoAdapter;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;