HHH-9388 : fix Entity Manager bug explicitly enabling ImprovedNamingStrategyDelegator/LegacyNamingStrategyDelegator

This commit is contained in:
Gail Badner 2014-10-22 13:46:15 -07:00
parent 460e966214
commit b943525c80
3 changed files with 47 additions and 3 deletions

View File

@ -34,7 +34,7 @@ public class ImprovedNamingStrategyDelegator implements NamingStrategyDelegator,
private final NamingStrategyDelegate hbmNamingStrategyDelegate;
private final NamingStrategyDelegate jpaNamingStrategyDelegate;
private ImprovedNamingStrategyDelegator() {
public ImprovedNamingStrategyDelegator() {
this(
new HbmNamingStrategyDelegate(),
new JpaNamingStrategyDelegate()

View File

@ -45,7 +45,7 @@ public class LegacyNamingStrategyDelegator
private final NamingStrategyDelegate hbmNamingStrategyDelegate;
private final NamingStrategyDelegate jpaNamingStrategyDelegate;
private LegacyNamingStrategyDelegator() {
public LegacyNamingStrategyDelegator() {
this( EJB3NamingStrategy.INSTANCE );
}

View File

@ -30,6 +30,7 @@ import javax.persistence.PersistenceException;
import org.junit.Test;
import org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator;
import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator;
import org.hibernate.cfg.naming.NamingStrategyDelegator;
import org.hibernate.ejb.AvailableSettings;
@ -76,7 +77,50 @@ public class NamingStrategyDelegatorConfigurationTest extends BaseUnitTestCase {
);
}
// configure NamingStrategyDelegator
// configure ImprovedNamingStrategyDelegator
{
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter();
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
adapter,
Collections.singletonMap(
AvailableSettings.NAMING_STRATEGY_DELEGATOR,
ImprovedNamingStrategyDelegator.class.getName()
)
);
assertEquals( null, builder.getConfigurationValues().get( AvailableSettings.NAMING_STRATEGY ) );
builder.build();
assertEquals(
ImprovedNamingStrategyDelegator.class.getName(),
builder.getConfigurationValues().get( AvailableSettings.NAMING_STRATEGY_DELEGATOR )
);
final NamingStrategyDelegator namingStrategyDelegator =
builder.getHibernateConfiguration().getNamingStrategyDelegator();
assertTrue( ImprovedNamingStrategyDelegator.class.isInstance( namingStrategyDelegator ) );
}
// configure LegacyNamingStrategyDelegator
{
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter();
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
adapter,
Collections.singletonMap(
AvailableSettings.NAMING_STRATEGY_DELEGATOR,
LegacyNamingStrategyDelegator.class.getName()
)
);
assertEquals( null, builder.getConfigurationValues().get( AvailableSettings.NAMING_STRATEGY ) );
builder.build();
assertEquals(
LegacyNamingStrategyDelegator.class.getName(),
builder.getConfigurationValues().get( AvailableSettings.NAMING_STRATEGY_DELEGATOR )
);
final NamingStrategyDelegator namingStrategyDelegator =
builder.getHibernateConfiguration().getNamingStrategyDelegator();
assertTrue( LegacyNamingStrategyDelegator.class.isInstance( namingStrategyDelegator ) );
}
// configure custom NamingStrategyDelegator
{
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter();
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(