HHH-14837 - Move to Jakarta EE

- fixups
This commit is contained in:
Steve Ebersole 2021-09-23 15:01:29 -05:00
parent 47b58f7fa2
commit a9387033b2
8 changed files with 318 additions and 158 deletions

View File

@ -252,10 +252,10 @@ if ( gradle.ext.javaToolchainEnabled ) {
}
class HeapDumpPathProvider implements CommandLineArgumentProvider {
// @InputFile
@OutputFile
@OutputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
// @Optional
Provider<RegularFile> path
Provider<Directory> path
// File path
@Override
@ -276,7 +276,7 @@ tasks.withType( Test.class ).each { test ->
}
test.jvmArgumentProviders.add(
new HeapDumpPathProvider( path: project.layout.buildDirectory.file("OOM-dump.hprof") )
new HeapDumpPathProvider( path: project.layout.buildDirectory.dir("OOM-dump") )
// new HeapDumpPathProvider( path: project.file( "${buildDir}/OOM-dump.hprof" ) )
)

View File

@ -32,9 +32,7 @@ javadoc {
encoding = 'UTF-8'
links += [
'https://docs.oracle.com/javase/8/docs/api/',
// 'https://docs.jboss.org/hibernate/beanvalidation/spec/2.0/api/',
// 'https://docs.jboss.org/cdi/api/2.0/',
'https://jakarta.ee/specifications/platform/10/apidocs/'
'https://jakarta.ee/specifications/platform/9/apidocs/'
]
tags = [ "apiNote", 'implSpec', 'implNote', 'todo' ]

View File

@ -61,16 +61,16 @@ dependencies {
testImplementation libraries.jodaTime
testImplementation libraries.assertj
testImplementation libraries.jakarta_cdi
testImplementation libraries.jboss_ejb_spec_jar
testImplementation libraries.jboss_annotation_spec_jar
// testImplementation libraries.jboss_ejb_spec_jar
// testImplementation libraries.jboss_annotation_spec_jar
testRuntimeOnly "org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final"
// testRuntimeOnly "org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final"
testRuntimeOnly libraries.jakarta_el
testRuntimeOnly 'jaxen:jaxen:1.1'
// testRuntimeOnly 'jaxen:jaxen:1.1'
testRuntimeOnly libraries.byteBuddy
testRuntimeOnly libraries.jakarta_weld
testRuntimeOnly libraries.atomikos
testRuntimeOnly libraries.atomikos_jta
// testRuntimeOnly libraries.atomikos
// testRuntimeOnly libraries.atomikos_jta
testRuntimeOnly libraries.wildfly_transaction_client
testAnnotationProcessor project( ':hibernate-jpamodelgen' )

View File

@ -151,7 +151,7 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
/**
* Used to pass along any discovered validator factory.
*/
String JPA_VALIDATION_FACTORY = "jakarta.persistence.validation.factory";
String JPA_VALIDATION_FACTORY = "javax.persistence.validation.factory";
/**
* Used to coordinate with bean validators

View File

@ -17,13 +17,10 @@ import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import java.util.function.Consumer;
import javax.sql.DataSource;
import org.hibernate.Internal;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.CacheRegionDefinition;
@ -60,7 +57,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.EntityManagerMessageLogger;
import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.internal.util.NullnessHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
@ -88,6 +84,15 @@ import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
import org.jboss.jandex.Index;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import static org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY;
import static org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER;
import static org.hibernate.cfg.AvailableSettings.CLASSLOADERS;
import static org.hibernate.cfg.AvailableSettings.DATASOURCE;
import static org.hibernate.cfg.AvailableSettings.DRIVER;
import static org.hibernate.cfg.AvailableSettings.JACC_CONTEXT_ID;
@ -101,6 +106,7 @@ import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JTA_DATASOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_NON_JTA_DATASOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_SHARED_CACHE_MODE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_TRANSACTION_TYPE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER;
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_PASSWORD;
@ -110,13 +116,17 @@ import static org.hibernate.cfg.AvailableSettings.JPA_JTA_DATASOURCE;
import static org.hibernate.cfg.AvailableSettings.JPA_NON_JTA_DATASOURCE;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_TRANSACTION_TYPE;
import static org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY;
import static org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_MODE;
import static org.hibernate.cfg.AvailableSettings.PASS;
import static org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY;
import static org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME;
import static org.hibernate.cfg.AvailableSettings.TC_CLASSLOADER;
import static org.hibernate.cfg.AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY;
import static org.hibernate.cfg.AvailableSettings.URL;
import static org.hibernate.cfg.AvailableSettings.USER;
import static org.hibernate.internal.HEMLogging.messageLogger;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
import static org.hibernate.jpa.AvailableSettings.CFG_FILE;
import static org.hibernate.jpa.AvailableSettings.CLASS_CACHE_PREFIX;
import static org.hibernate.jpa.AvailableSettings.COLLECTION_CACHE_PREFIX;
@ -179,28 +189,40 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
public EntityManagerFactoryBuilderImpl(PersistenceUnitDescriptor persistenceUnit, Map integrationSettings) {
this( persistenceUnit, integrationSettings, null, null );
this( persistenceUnit, integrationSettings, null, null, null );
}
public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings,
ClassLoader providedClassLoader ) {
this( persistenceUnit, integrationSettings, providedClassLoader, null);
this( persistenceUnit, integrationSettings, providedClassLoader, null, null );
}
public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings,
ClassLoaderService providedClassLoaderService ) {
this( persistenceUnit, integrationSettings, null, providedClassLoaderService);
this( persistenceUnit, integrationSettings, null, providedClassLoaderService, null );
}
/**
* For tests only
*/
@Internal
public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnitDescriptor,
Map integration,
Consumer<MergedSettings> mergedSettingsBaseline) {
this( persistenceUnitDescriptor, integration, null, null, mergedSettingsBaseline );
}
private EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings,
ClassLoader providedClassLoader,
ClassLoaderService providedClassLoaderService) {
ClassLoaderService providedClassLoaderService,
Consumer<MergedSettings> mergedSettingsBaseline) {
LogHelper.logPersistenceUnitInformation( persistenceUnit );
@ -224,11 +246,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
providedClassLoader,
providedClassLoaderService
);
try {
// merge configuration sources and build the "standard" service registry
final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr );
final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder );
final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder, mergedSettingsBaseline );
// flush before completion validation
if ( "true".equals( mergedSettings.configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) {
@ -272,9 +295,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
metamodelBuilder.getBootstrapContext()
);
final Object validatorFactory = configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY );
final Object validatorFactory = configurationValues.get( JAKARTA_JPA_VALIDATION_FACTORY );
if ( validatorFactory == null ) {
withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY ) );
final Object legacyValidatorFactory = configurationValues.get( JPA_VALIDATION_FACTORY );
if ( legacyValidatorFactory != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_VALIDATION_FACTORY, JAKARTA_JPA_VALIDATION_FACTORY );
}
withValidatorFactory( legacyValidatorFactory );
}
else {
withValidatorFactory( validatorFactory );
@ -442,15 +469,15 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
bsrBuilder.applyClassLoader( providedClassLoader );
}
final ClassLoader appClassLoader = (ClassLoader) integrationSettings.get( org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER );
final ClassLoader appClassLoader = (ClassLoader) integrationSettings.get( APP_CLASSLOADER );
if ( appClassLoader != null ) {
LOG.debugf(
"Found use of deprecated `%s` setting; use `%s` instead.",
org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER,
org.hibernate.cfg.AvailableSettings.CLASSLOADERS
APP_CLASSLOADER,
CLASSLOADERS
);
}
final Object classLoadersSetting = integrationSettings.get( org.hibernate.cfg.AvailableSettings.CLASSLOADERS );
final Object classLoadersSetting = integrationSettings.get( CLASSLOADERS );
if ( classLoadersSetting != null ) {
if ( java.util.Collection.class.isInstance( classLoadersSetting ) ) {
for ( ClassLoader classLoader : (java.util.Collection<ClassLoader>) classLoadersSetting ) {
@ -470,7 +497,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
//configurationValues not assigned yet, using directly the properties of the PU
Properties puProperties = persistenceUnit.getProperties();
if( puProperties != null ) {
final String tcclLookupPrecedence = puProperties.getProperty( org.hibernate.cfg.AvailableSettings.TC_CLASSLOADER );
final String tcclLookupPrecedence = puProperties.getProperty( TC_CLASSLOADER );
if( tcclLookupPrecedence != null ) {
bsrBuilder.applyTcclLookupPrecedence( TcclLookupPrecedence.valueOf( tcclLookupPrecedence.toUpperCase( Locale.ROOT ) ) );
}
@ -502,8 +529,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
private MergedSettings mergeSettings(
PersistenceUnitDescriptor persistenceUnit,
Map<?,?> integrationSettings,
StandardServiceRegistryBuilder ssrBuilder) {
StandardServiceRegistryBuilder ssrBuilder,
Consumer<MergedSettings> mergedSettingsBaseline) {
final MergedSettings mergedSettings = new MergedSettings();
if ( mergedSettingsBaseline != null ) {
mergedSettingsBaseline.accept( mergedSettings );
}
mergedSettings.processPersistenceUnitDescriptorProperties( persistenceUnit );
// see if the persistence.xml settings named a Hibernate config file....
@ -599,12 +630,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// normalize ValidationMode
final Object intgValidationMode = integrationSettingsCopy.remove( JPA_VALIDATION_MODE );
final Object jakartaIntgValidationMode = integrationSettingsCopy.remove( JAKARTA_JPA_VALIDATION_MODE );
if ( intgValidationMode != null ) {
mergedSettings.configurationValues.put( JPA_VALIDATION_MODE, intgValidationMode );
}
else if ( jakartaIntgValidationMode != null ) {
if ( jakartaIntgValidationMode != null ) {
mergedSettings.configurationValues.put( JAKARTA_JPA_VALIDATION_MODE, jakartaIntgValidationMode );
}
else if ( intgValidationMode != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_VALIDATION_MODE, JAKARTA_JPA_VALIDATION_MODE );
mergedSettings.configurationValues.put( JPA_VALIDATION_MODE, intgValidationMode );
}
else if ( persistenceUnit.getValidationMode() != null ) {
mergedSettings.configurationValues.put( JPA_VALIDATION_MODE, persistenceUnit.getValidationMode() );
mergedSettings.configurationValues.put( JAKARTA_JPA_VALIDATION_MODE, persistenceUnit.getValidationMode() );
@ -617,14 +649,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
mergedSettings.configurationValues.put( JAKARTA_JPA_SHARED_CACHE_MODE, jakartaIntgCacheMode );
}
else if ( intgCacheMode != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
JPA_SHARED_CACHE_MODE,
JAKARTA_JPA_SHARED_CACHE_MODE
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_SHARED_CACHE_MODE, JAKARTA_JPA_SHARED_CACHE_MODE );
mergedSettings.configurationValues.put( JPA_SHARED_CACHE_MODE, intgCacheMode );
}
else if ( persistenceUnit.getSharedCacheMode() != null ) {
mergedSettings.configurationValues.put( JAKARTA_JPA_SHARED_CACHE_MODE, persistenceUnit.getSharedCacheMode() );
mergedSettings.configurationValues.put( JPA_SHARED_CACHE_MODE, persistenceUnit.getSharedCacheMode() );
}
// Apply all "integration overrides" as the last step. By specification,
@ -653,24 +683,48 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
private void normalizeConnectionAccessUserAndPass(
HashMap<?, ?> integrationSettingsCopy,
MergedSettings mergedSettings) {
//noinspection unchecked
final Object effectiveUser = NullnessHelper.coalesceSuppliedValues(
() -> integrationSettingsCopy.remove( USER ),
() -> integrationSettingsCopy.remove( JPA_JDBC_USER ),
() -> integrationSettingsCopy.remove( JAKARTA_JPA_JDBC_USER ),
() -> {
final Object setting = integrationSettingsCopy.remove( JPA_JDBC_USER );
if ( setting != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_USER, JAKARTA_JPA_JDBC_USER );
}
return setting;
},
() -> extractPuProperty( persistenceUnit, USER ),
() -> extractPuProperty( persistenceUnit, JPA_JDBC_USER ),
() -> extractPuProperty( persistenceUnit, JAKARTA_JPA_JDBC_USER )
() -> extractPuProperty( persistenceUnit, JAKARTA_JPA_JDBC_USER ),
() -> {
final Object setting = extractPuProperty( persistenceUnit, JPA_JDBC_USER );
if ( setting != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_USER, JAKARTA_JPA_JDBC_USER );
}
return setting;
}
);
//noinspection unchecked
final Object effectivePass = NullnessHelper.coalesceSuppliedValues(
() -> integrationSettingsCopy.remove( PASS ),
() -> integrationSettingsCopy.remove( JPA_JDBC_PASSWORD ),
() -> integrationSettingsCopy.remove( JAKARTA_JPA_JDBC_PASSWORD ),
() -> {
final Object setting = integrationSettingsCopy.remove( JPA_JDBC_PASSWORD );
if ( setting != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_PASSWORD, JAKARTA_JPA_JDBC_PASSWORD );
}
return setting;
},
() -> extractPuProperty( persistenceUnit, PASS ),
() -> extractPuProperty( persistenceUnit, JPA_JDBC_PASSWORD ),
() -> extractPuProperty( persistenceUnit, JAKARTA_JPA_JDBC_PASSWORD )
() -> extractPuProperty( persistenceUnit, JAKARTA_JPA_JDBC_PASSWORD ),
() -> {
{
final Object setting = extractPuProperty( persistenceUnit, JPA_JDBC_PASSWORD );
if ( setting != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_PASSWORD, JAKARTA_JPA_JDBC_PASSWORD );
}
return setting;
}
}
);
if ( effectiveUser != null || effectivePass != null ) {
@ -687,14 +741,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
private void applyUserAndPass(Object effectiveUser, Object effectivePass, MergedSettings mergedSettings) {
if ( effectiveUser != null ) {
mergedSettings.configurationValues.put( USER, effectiveUser );
mergedSettings.configurationValues.put( JPA_JDBC_USER, effectiveUser );
mergedSettings.configurationValues.put( JAKARTA_JPA_JDBC_USER, effectiveUser );
mergedSettings.configurationValues.put( JPA_JDBC_USER, effectiveUser );
}
if ( effectivePass != null ) {
mergedSettings.configurationValues.put( PASS, effectivePass );
mergedSettings.configurationValues.put( JPA_JDBC_PASSWORD, effectivePass );
mergedSettings.configurationValues.put( JAKARTA_JPA_JDBC_PASSWORD, effectivePass );
mergedSettings.configurationValues.put( JPA_JDBC_PASSWORD, effectivePass );
}
}
@ -707,9 +761,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
MergedSettings mergedSettings) {
PersistenceUnitTransactionType txnType = null;
Object intgTxnType = integrationSettingsCopy.remove( JPA_TRANSACTION_TYPE );
Object intgTxnType = integrationSettingsCopy.remove( JAKARTA_JPA_TRANSACTION_TYPE );
if ( intgTxnType == null ) {
intgTxnType = integrationSettingsCopy.remove( JAKARTA_JPA_TRANSACTION_TYPE );
intgTxnType = integrationSettingsCopy.remove( JPA_TRANSACTION_TYPE );
if ( intgTxnType != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_TRANSACTION_TYPE, JAKARTA_JPA_TRANSACTION_TYPE );
}
}
if ( intgTxnType != null ) {
@ -719,10 +776,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
txnType = persistenceUnit.getTransactionType();
}
else {
Object puPropTxnType = mergedSettings.configurationValues.get( JPA_TRANSACTION_TYPE );
Object puPropTxnType = mergedSettings.configurationValues.get( JAKARTA_JPA_TRANSACTION_TYPE );
if ( puPropTxnType == null ) {
puPropTxnType = mergedSettings.configurationValues.get( JAKARTA_JPA_TRANSACTION_TYPE );
puPropTxnType = mergedSettings.configurationValues.get( JPA_TRANSACTION_TYPE );
if ( puPropTxnType != null ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_TRANSACTION_TYPE, JAKARTA_JPA_TRANSACTION_TYPE );
}
}
if ( puPropTxnType != null ) {
txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType( puPropTxnType );
}
@ -798,21 +859,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
if ( integrationSettingsCopy.containsKey( JPA_JTA_DATASOURCE ) ) {
final Object dataSourceRef = integrationSettingsCopy.remove( JPA_JTA_DATASOURCE );
if ( dataSourceRef != null ) {
applyDataSource(
dataSourceRef,
true,
integrationSettingsCopy,
mergedSettings
);
// EARLY EXIT!!
return;
}
}
if ( integrationSettingsCopy.containsKey( JAKARTA_JPA_JTA_DATASOURCE ) ) {
final Object dataSourceRef = integrationSettingsCopy.remove( JAKARTA_JPA_JTA_DATASOURCE );
if ( dataSourceRef != null ) {
@ -828,36 +874,37 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
if ( integrationSettingsCopy.containsKey( JPA_NON_JTA_DATASOURCE ) ) {
final Object dataSourceRef = integrationSettingsCopy.remove( JPA_NON_JTA_DATASOURCE );
if ( integrationSettingsCopy.containsKey( JPA_JTA_DATASOURCE ) ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_JTA_DATASOURCE, JAKARTA_JPA_JTA_DATASOURCE );
final Object dataSourceRef = integrationSettingsCopy.remove( JPA_JTA_DATASOURCE );
if ( dataSourceRef != null ) {
applyDataSource( dataSourceRef, true,integrationSettingsCopy, mergedSettings );
applyDataSource(
dataSourceRef,
false,
integrationSettingsCopy,
mergedSettings
);
// EARLY EXIT!!
return;
}
}
if ( integrationSettingsCopy.containsKey( JAKARTA_JPA_NON_JTA_DATASOURCE ) ) {
final Object dataSourceRef = integrationSettingsCopy.remove( JAKARTA_JPA_NON_JTA_DATASOURCE );
applyDataSource( dataSourceRef, false, integrationSettingsCopy, mergedSettings );
// EARLY EXIT!!
return;
}
if ( integrationSettingsCopy.containsKey( JAKARTA_JPA_NON_JTA_DATASOURCE ) ) {
final Object dataSourceRef = integrationSettingsCopy.remove( JAKARTA_JPA_NON_JTA_DATASOURCE );
if ( integrationSettingsCopy.containsKey( JPA_NON_JTA_DATASOURCE ) ) {
DEPRECATION_LOGGER.deprecatedSetting( JPA_NON_JTA_DATASOURCE, JAKARTA_JPA_NON_JTA_DATASOURCE );
applyDataSource(
dataSourceRef,
false,
integrationSettingsCopy,
mergedSettings
);
final Object dataSourceRef = integrationSettingsCopy.remove( JPA_NON_JTA_DATASOURCE );
applyDataSource( dataSourceRef, false, integrationSettingsCopy, mergedSettings );
// EARLY EXIT!!
return;
}
if ( integrationSettingsCopy.containsKey( URL ) ) {
// these have precedence over the JPA ones
// hibernate-specific settings have precedence over the JPA ones
final Object integrationJdbcUrl = integrationSettingsCopy.get( URL );
if ( integrationJdbcUrl != null ) {
//noinspection unchecked
@ -869,10 +916,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
() -> {
final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, integrationSettingsCopy );
if ( driver != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER,
org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_DRIVER
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JPA_JDBC_DRIVER );
}
return driver;
},
@ -881,10 +925,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
() -> {
final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues );
if ( driver != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER,
org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_DRIVER
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JPA_JDBC_DRIVER );
}
return driver;
}
@ -919,10 +960,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
if ( integrationSettingsCopy.containsKey( JPA_JDBC_URL ) ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.cfg.AvailableSettings.JPA_JDBC_URL,
org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_URL
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_URL, JAKARTA_JPA_JDBC_URL );
final Object integrationJdbcUrl = integrationSettingsCopy.get( JPA_JDBC_URL );
@ -934,20 +972,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
() -> {
final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, integrationSettingsCopy );
if ( driver != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER,
org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_DRIVER
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JPA_JDBC_DRIVER );
}
return driver;
},
() -> {
final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues );
if ( driver != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER,
org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_DRIVER
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JPA_JDBC_DRIVER );
}
return driver;
}
@ -962,24 +994,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
if ( persistenceUnit.getJtaDataSource() != null ) {
applyDataSource(
persistenceUnit.getJtaDataSource(),
true,
integrationSettingsCopy,
mergedSettings
);
applyDataSource( persistenceUnit.getJtaDataSource(), true, integrationSettingsCopy, mergedSettings );
// EARLY EXIT!!
return;
}
if ( persistenceUnit.getNonJtaDataSource() != null ) {
applyDataSource(
persistenceUnit.getNonJtaDataSource(),
false,
integrationSettingsCopy,
mergedSettings
);
applyDataSource( persistenceUnit.getNonJtaDataSource(), false, integrationSettingsCopy, mergedSettings );
// EARLY EXIT!!
return;
@ -1018,29 +1040,19 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
if ( mergedSettings.configurationValues.containsKey( JPA_JDBC_URL ) ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.cfg.AvailableSettings.JPA_JDBC_URL,
org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_URL
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_URL, JAKARTA_JPA_JDBC_URL );
final Object url = mergedSettings.configurationValues.get( JPA_JDBC_URL );
if ( url != null && ( ! ( url instanceof String ) || StringHelper.isNotEmpty( (String) url ) ) ) {
final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues );
if ( driver != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER,
org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_DRIVER
);
DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JPA_JDBC_DRIVER );
}
applyJdbcSettings(
url,
driver,
integrationSettingsCopy,
mergedSettings
);
applyJdbcSettings( url, driver, integrationSettingsCopy, mergedSettings );
// EARLY EXIT!!
//noinspection UnnecessaryReturnStatement
return;
}
}
@ -1360,7 +1372,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
metamodelBuilder.applyScanEnvironment( new StandardJpaScanEnvironmentImpl( persistenceUnit ) );
metamodelBuilder.applyScanOptions(
new StandardScanOptions(
(String) configurationValues.get( org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY ),
(String) configurationValues.get( SCANNER_DISCOVERY ),
persistenceUnit.isExcludeUnlistedClasses()
)
);
@ -1515,7 +1527,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
( ( SessionFactoryBuilderImplementor ) sfBuilder ).disableJtaTransactionAccess();
}
final boolean allowRefreshDetachedEntity = readBooleanConfigurationValue( org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY );
final boolean allowRefreshDetachedEntity = readBooleanConfigurationValue( ALLOW_REFRESH_DETACHED_ENTITY );
if ( !allowRefreshDetachedEntity ) {
( (SessionFactoryBuilderImplementor) sfBuilder ).disableRefreshDetachedEntity();
}
@ -1576,7 +1588,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
return "[PersistenceUnit: " + persistenceUnit.getName() + "] ";
}
private static class MergedSettings {
public static class MergedSettings {
private final Map configurationValues = new ConcurrentHashMap( 16, 0.75f, 1 );
private Map<String, JaccPermissionDeclarations> jaccPermissionsByContextId;

View File

@ -8,14 +8,17 @@ package org.hibernate.jpa.boot.spi;
import java.net.URL;
import java.util.Map;
import jakarta.persistence.spi.PersistenceUnitInfo;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import java.util.function.Consumer;
import org.hibernate.Internal;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
import jakarta.persistence.spi.PersistenceUnitInfo;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
/**
* Entry into the bootstrap process.
*
@ -82,6 +85,17 @@ public final class Bootstrap {
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoaderService );
}
/**
* For tests only
*/
@Internal
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitDescriptor persistenceUnitDescriptor,
Map integration,
Consumer<EntityManagerFactoryBuilderImpl.MergedSettings> mergedSettingsBaseline) {
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, mergedSettingsBaseline );
}
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitInfo persistenceUnitInfo,
Map integration) {
@ -101,4 +115,15 @@ public final class Bootstrap {
ClassLoaderService providedClassLoaderService) {
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, providedClassLoaderService );
}
/**
* For tests only
*/
@Internal
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitInfo persistenceUnitInfo,
Map integration,
Consumer<EntityManagerFactoryBuilderImpl.MergedSettings> mergedSettingsBaseline) {
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, mergedSettingsBaseline );
}
}

View File

@ -7,18 +7,23 @@
package org.hibernate.orm.test.jpa.ejb3configuration;
import java.util.Collections;
import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.testing.orm.jpa.PersistenceUnitInfoAdapter;
import org.hibernate.testing.orm.jpa.PersistenceUnitInfoAdapter;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.jupiter.api.Test;
import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ -30,7 +35,12 @@ import static org.junit.jupiter.api.Assertions.fail;
@BaseUnitTest
public class ConfigurationObjectSettingTest {
@Test
public void testContainerBootstrapSharedCacheMode() {
public void testSharedCacheMode() {
verifyCacheMode( AvailableSettings.JAKARTA_JPA_SHARED_CACHE_MODE );
verifyCacheMode( AvailableSettings.JPA_SHARED_CACHE_MODE );
}
private void verifyCacheMode(String settingName) {
// first, via the integration vars
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
EntityManagerFactoryBuilderImpl builder = null;
@ -38,18 +48,19 @@ public class ConfigurationObjectSettingTest {
// as object
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
empty,
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
Collections.singletonMap( settingName, SharedCacheMode.DISABLE_SELECTIVE )
);
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
assertThat( builder.getConfigurationValues().get( settingName ) ).isEqualTo( SharedCacheMode.DISABLE_SELECTIVE );
}
builder.cancel();
{
// as string
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
empty,
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE.name() )
Collections.singletonMap( settingName, SharedCacheMode.DISABLE_SELECTIVE.name() )
);
assertEquals( SharedCacheMode.DISABLE_SELECTIVE.name(), builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
assertThat( builder.getConfigurationValues().get( settingName ) ).isEqualTo( SharedCacheMode.DISABLE_SELECTIVE.name() );
}
builder.cancel();
@ -65,7 +76,7 @@ public class ConfigurationObjectSettingTest {
adapter,
null
);
assertEquals( SharedCacheMode.ENABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
assertEquals( SharedCacheMode.ENABLE_SELECTIVE, builder.getConfigurationValues().get( settingName ) );
}
builder.cancel();
@ -73,15 +84,20 @@ public class ConfigurationObjectSettingTest {
{
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
adapter,
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
Collections.singletonMap( settingName, SharedCacheMode.DISABLE_SELECTIVE )
);
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( settingName ) );
}
builder.cancel();
}
@Test
public void testContainerBootstrapValidationMode() {
public void testValidationMode() {
verifyValidationMode( AvailableSettings.JAKARTA_JPA_VALIDATION_MODE );
verifyValidationMode( AvailableSettings.JPA_VALIDATION_MODE );
}
private void verifyValidationMode(String settingName) {
// first, via the integration vars
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
EntityManagerFactoryBuilderImpl builder = null;
@ -89,18 +105,19 @@ public class ConfigurationObjectSettingTest {
// as object
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
empty,
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK )
Collections.singletonMap( settingName, ValidationMode.CALLBACK )
);
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
assertThat( builder.getConfigurationValues().get( settingName ) ).isEqualTo( ValidationMode.CALLBACK );
}
builder.cancel();
{
// as string
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
empty,
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK.name() )
Collections.singletonMap( settingName, ValidationMode.CALLBACK.name() )
);
assertEquals( ValidationMode.CALLBACK.name(), builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
assertThat( builder.getConfigurationValues().get( settingName ) ).isEqualTo( ValidationMode.CALLBACK.name() );
}
builder.cancel();
@ -116,7 +133,7 @@ public class ConfigurationObjectSettingTest {
adapter,
null
);
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
assertThat( builder.getConfigurationValues().get( settingName ) ).isEqualTo( ValidationMode.CALLBACK );
}
builder.cancel();
@ -124,21 +141,26 @@ public class ConfigurationObjectSettingTest {
{
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
adapter,
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.NONE )
Collections.singletonMap( settingName, ValidationMode.NONE )
);
assertEquals( ValidationMode.NONE, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
assertThat( builder.getConfigurationValues().get( settingName ) ).isEqualTo( ValidationMode.NONE );
}
builder.cancel();
}
@Test
public void testContainerBootstrapValidationFactory() {
public void testValidationFactory() {
verifyValidatorFactory( AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY );
verifyValidatorFactory( AvailableSettings.JPA_VALIDATION_FACTORY );
}
private void verifyValidatorFactory(String settingName) {
final Object token = new Object();
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter();
try {
Bootstrap.getEntityManagerFactoryBuilder(
adapter,
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_FACTORY, token )
Collections.singletonMap( settingName, token )
).cancel();
fail( "Was expecting error as token did not implement ValidatorFactory" );
}
@ -147,4 +169,107 @@ public class ConfigurationObjectSettingTest {
// and the pertinent info is in a cause
}
}
@Test
// @FailureExpected(
// reason = "this is unfortunate to not be able to test. it fails because the values from `hibernate.properties` " +
// "name the Hibernate-specific settings, which always take precedence. testing this needs to be able to erase " +
// "those entries in the ConfigurationService Map"
// )
public void testJdbcSettings() {
verifyJdbcSettings(
AvailableSettings.JAKARTA_JPA_JDBC_URL,
AvailableSettings.JAKARTA_JPA_JDBC_DRIVER,
AvailableSettings.JAKARTA_JPA_JDBC_USER,
AvailableSettings.JAKARTA_JPA_JDBC_PASSWORD
);
verifyJdbcSettings(
AvailableSettings.JPA_JDBC_URL,
AvailableSettings.JPA_JDBC_DRIVER,
AvailableSettings.JPA_JDBC_USER,
AvailableSettings.JPA_JDBC_PASSWORD
);
}
private void verifyJdbcSettings(String jdbcUrl, String jdbcDriver, String jdbcUser, String jdbcPassword) {
final String urlValue = "some:url";
final String driverValue = "some.jdbc.Driver";
final String userValue = "goofy";
final String passwordValue = "goober";
// first, via the integration vars
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
EntityManagerFactoryBuilderImpl builder = null;
{
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
empty,
toMap(
jdbcUrl, urlValue,
jdbcDriver, driverValue,
jdbcUser, userValue,
jdbcPassword, passwordValue
),
mergedSettings -> mergedSettings.getConfigurationValues().clear()
);
assertThat( builder.getConfigurationValues().get( jdbcUrl ) ).isEqualTo( urlValue );
assertThat( builder.getConfigurationValues().get( jdbcDriver ) ).isEqualTo( driverValue );
assertThat( builder.getConfigurationValues().get( jdbcUser ) ).isEqualTo( userValue );
assertThat( builder.getConfigurationValues().get( jdbcPassword ) ).isEqualTo( passwordValue );
builder.cancel();
}
PersistenceUnitInfoAdapter pui = new PersistenceUnitInfoAdapter();
applyToMap(
pui.getProperties(),
jdbcUrl, urlValue,
jdbcDriver, driverValue,
jdbcUser, userValue,
jdbcPassword, passwordValue
);
{
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
pui,
null,
mergedSettings -> mergedSettings.getConfigurationValues().clear()
);
assertThat( builder.getConfigurationValues().get( jdbcUrl ) ).isEqualTo( urlValue );
assertThat( builder.getConfigurationValues().get( jdbcDriver ) ).isEqualTo( driverValue );
assertThat( builder.getConfigurationValues().get( jdbcUser ) ).isEqualTo( userValue );
assertThat( builder.getConfigurationValues().get( jdbcPassword ) ).isEqualTo( passwordValue );
builder.cancel();
}
}
private static Map<String,String> toMap(String... pairs) {
assert pairs.length %2 == 0;
if ( pairs.length == 2 ) {
return Collections.singletonMap( pairs[0], pairs[1] );
}
final Map<String,String> result = new HashMap<>();
for ( int i = 0; i < pairs.length; i+=2 ) {
result.put( pairs[i], pairs[i+1] );
}
return result;
}
private static void applyToMap(Map<String,String> map, String... pairs) {
assert pairs.length %2 == 0;
for ( int i = 0; i < pairs.length; i+=2 ) {
map.put( pairs[i], pairs[i+1] );
}
}
private static void applyToMap(Properties map, String... pairs) {
assert pairs.length %2 == 0;
for ( int i = 0; i < pairs.length; i+=2 ) {
map.put( pairs[i], pairs[i+1] );
}
}
}