HHH-14273 Support for jakarta.persistence prefixed String properties

This commit is contained in:
Christian Beikov 2021-04-20 13:11:26 +02:00
parent cd97e59d21
commit 14b35bb3b6
23 changed files with 792 additions and 61 deletions

View File

@ -96,6 +96,11 @@ public class QueryHints {
*/
public static final String TIMEOUT_JPA = "javax.persistence.query.timeout";
/**
* Apply a JPA query timeout, which is defined in <b>milliseconds</b>.
*/
public static final String TIMEOUT_JAKARTA_JPA = "jakarta.persistence.query.timeout";
/**
* Available to apply lock mode to a native SQL query since JPA requires that
* {@link javax.persistence.Query#setLockMode} throw an IllegalStateException if called for a native query.

View File

@ -85,6 +85,7 @@ public class ClassLoaderAccessImpl implements ClassLoaderAccess {
// classes in any of these packages are safe to load through the "live" ClassLoader
return name.startsWith( "java." )
|| name.startsWith( "javax." )
|| name.startsWith( "jakarta." )
|| name.startsWith( "org.hibernate." );
}

View File

@ -659,7 +659,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
);
this.sharedCacheMode = configService.getSetting(
"javax.persistence.sharedCache.mode",
AvailableSettings.JPA_SHARED_CACHE_MODE,
new ConfigurationService.Converter<SharedCacheMode>() {
@Override
public SharedCacheMode convert(Object value) {
@ -674,7 +674,24 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
return SharedCacheMode.valueOf( value.toString() );
}
},
SharedCacheMode.UNSPECIFIED
configService.getSetting(
AvailableSettings.JAKARTA_JPA_SHARED_CACHE_MODE,
new ConfigurationService.Converter<SharedCacheMode>() {
@Override
public SharedCacheMode convert(Object value) {
if ( value == null ) {
return null;
}
if ( SharedCacheMode.class.isInstance( value ) ) {
return (SharedCacheMode) value;
}
return SharedCacheMode.valueOf( value.toString() );
}
},
SharedCacheMode.UNSPECIFIED
)
);
this.defaultCacheAccessType = configService.getSetting(

View File

@ -272,8 +272,14 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
( (ConfigurationServiceImpl) cfgService ).injectServices( (ServiceRegistryImplementor) serviceRegistry );
}
this.beanManagerReference = configurationSettings.get( "javax.persistence.bean.manager" );
this.validatorFactoryReference = configurationSettings.get( "javax.persistence.validation.factory" );
this.beanManagerReference = configurationSettings.getOrDefault(
AvailableSettings.CDI_BEAN_MANAGER,
configurationSettings.get( AvailableSettings.JAKARTA_CDI_BEAN_MANAGER )
);
this.validatorFactoryReference = configurationSettings.getOrDefault(
AvailableSettings.JPA_VALIDATION_FACTORY,
configurationSettings.get( AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY )
);
this.sessionFactoryName = (String) configurationSettings.get( SESSION_FACTORY_NAME );
this.sessionFactoryNameAlsoJndiName = cfgService.getSetting(

View File

@ -208,6 +208,185 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
String CDI_BEAN_MANAGER = "javax.persistence.bean.manager";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Jakarta JPA defined settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* The name of the {@link javax.persistence.spi.PersistenceProvider} implementor
* <p/>
* See JPA 2 sections 9.4.3 and 8.2.1.4
*/
String JAKARTA_JPA_PERSISTENCE_PROVIDER = "jakarta.persistence.provider";
/**
* The type of transactions supported by the entity managers.
* <p/>
* See JPA 2 sections 9.4.3 and 8.2.1.2
*/
String JAKARTA_JPA_TRANSACTION_TYPE = "jakarta.persistence.transactionType";
/**
* The JNDI name of a JTA {@link javax.sql.DataSource}.
* <p/>
* See JPA 2 sections 9.4.3 and 8.2.1.5
*/
String JAKARTA_JPA_JTA_DATASOURCE = "jakarta.persistence.jtaDataSource";
/**
* The JNDI name of a non-JTA {@link javax.sql.DataSource}.
* <p/>
* See JPA 2 sections 9.4.3 and 8.2.1.5
*/
String JAKARTA_JPA_NON_JTA_DATASOURCE = "jakarta.persistence.nonJtaDataSource";
/**
* The name of a JDBC driver to use to connect to the database.
* <p/>
* Used in conjunction with {@link #JPA_JDBC_URL}, {@link #JPA_JDBC_USER} and {@link #JPA_JDBC_PASSWORD}
* to define how to make connections to the database in lieu of
* a datasource (either {@link #JPA_JTA_DATASOURCE} or {@link #JPA_NON_JTA_DATASOURCE}).
* <p/>
* See section 8.2.1.9
*/
String JAKARTA_JPA_JDBC_DRIVER = "jakarta.persistence.jdbc.driver";
/**
* The JDBC connection url to use to connect to the database.
* <p/>
* Used in conjunction with {@link #JPA_JDBC_DRIVER}, {@link #JPA_JDBC_USER} and {@link #JPA_JDBC_PASSWORD}
* to define how to make connections to the database in lieu of
* a datasource (either {@link #JPA_JTA_DATASOURCE} or {@link #JPA_NON_JTA_DATASOURCE}).
* <p/>
* See section 8.2.1.9
*/
String JAKARTA_JPA_JDBC_URL = "jakarta.persistence.jdbc.url";
/**
* The JDBC connection user name.
* <p/>
* Used in conjunction with {@link #JPA_JDBC_DRIVER}, {@link #JPA_JDBC_URL} and {@link #JPA_JDBC_PASSWORD}
* to define how to make connections to the database in lieu of
* a datasource (either {@link #JPA_JTA_DATASOURCE} or {@link #JPA_NON_JTA_DATASOURCE}).
* <p/>
* See section 8.2.1.9
*/
String JAKARTA_JPA_JDBC_USER = "jakarta.persistence.jdbc.user";
/**
* The JDBC connection password.
* <p/>
* Used in conjunction with {@link #JPA_JDBC_DRIVER}, {@link #JPA_JDBC_URL} and {@link #JPA_JDBC_USER}
* to define how to make connections to the database in lieu of
* a datasource (either {@link #JPA_JTA_DATASOURCE} or {@link #JPA_NON_JTA_DATASOURCE}).
* <p/>
* See JPA 2 section 8.2.1.9
*/
String JAKARTA_JPA_JDBC_PASSWORD = "jakarta.persistence.jdbc.password";
/**
* Used to indicate whether second-level (what JPA terms shared cache) caching is
* enabled as per the rules defined in JPA 2 section 3.1.7.
* <p/>
* See JPA 2 sections 9.4.3 and 8.2.1.7
* @see javax.persistence.SharedCacheMode
*/
String JAKARTA_JPA_SHARED_CACHE_MODE = "jakarta.persistence.sharedCache.mode";
/**
* NOTE : Not a valid EMF property...
* <p/>
* Used to indicate if the provider should attempt to retrieve requested data
* in the shared cache.
*
* @see javax.persistence.CacheRetrieveMode
*/
String JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE ="jakarta.persistence.cache.retrieveMode";
/**
* NOTE : Not a valid EMF property...
* <p/>
* Used to indicate if the provider should attempt to store data loaded from the database
* in the shared cache.
*
* @see javax.persistence.CacheStoreMode
*/
String JAKARTA_JPA_SHARED_CACHE_STORE_MODE ="jakarta.persistence.cache.storeMode";
/**
* Used to indicate what form of automatic validation is in effect as per rules defined
* in JPA 2 section 3.6.1.1
* <p/>
* See JPA 2 sections 9.4.3 and 8.2.1.8
* @see javax.persistence.ValidationMode
*/
String JAKARTA_JPA_VALIDATION_MODE = "jakarta.persistence.validation.mode";
/**
* Used to pass along any discovered validator factory.
*/
String JAKARTA_JPA_VALIDATION_FACTORY = "jakarta.persistence.validation.factory";
/**
* Used to coordinate with bean validators
* <p/>
* See JPA 2 section 8.2.1.9
*/
String JAKARTA_JPA_PERSIST_VALIDATION_GROUP = "jakarta.persistence.validation.group.pre-persist";
/**
* Used to coordinate with bean validators
* <p/>
* See JPA 2 section 8.2.1.9
*/
String JAKARTA_JPA_UPDATE_VALIDATION_GROUP = "jakarta.persistence.validation.group.pre-update";
/**
* Used to coordinate with bean validators
* <p/>
* See JPA 2 section 8.2.1.9
*/
String JAKARTA_JPA_REMOVE_VALIDATION_GROUP = "jakarta.persistence.validation.group.pre-remove";
/**
* Used to request (hint) a pessimistic lock scope.
* <p/>
* See JPA 2 sections 8.2.1.9 and 3.4.4.3
*/
String JAKARTA_JPA_LOCK_SCOPE = "jakarta.persistence.lock.scope";
/**
* Used to request (hint) a pessimistic lock timeout (in milliseconds).
* <p/>
* See JPA 2 sections 8.2.1.9 and 3.4.4.3
*/
String JAKARTA_JPA_LOCK_TIMEOUT = "jakarta.persistence.lock.timeout";
/**
* Used to pass along the CDI BeanManager, if any, to be used.
*
* According to JPA, strictly, the BeanManager should be passed in
* at boot-time and be ready for use at that time. However not all
* environments can do this (WildFly e.g.). To accommodate such
* environments, Hibernate provides 2 options:
*
* * a proprietary CDI extension SPI (that we have proposed to
* the CDI spec group as a standard option) that can be used
* to provide delayed BeanManager access. To use this solution,
* the reference passed as the BeanManager during bootstrap
* should be typed as {@link ExtendedBeanManager}
* * delayed access to the BeanManager reference. Here, Hibernate
* will not access the reference passed as the BeanManager during
* bootstrap until it is first needed. Note however that this has
* the effect of delaying any deployment problems until after
* bootstrapping.
*
* This setting is used to configure Hibernate ORM's access to
* the BeanManager (either directly or via {@link ExtendedBeanManager}).
*/
String JAKARTA_CDI_BEAN_MANAGER = "jakarta.persistence.bean.manager";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// BootstrapServiceRegistry level settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -1486,6 +1665,172 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
*/
String HBM2DDL_CREATE_SCHEMAS = "javax.persistence.create-database-schemas";
/**
* Setting to perform SchemaManagementTool actions against the database directly via JDBC
* automatically as part of the SessionFactory lifecycle. Valid options are defined by the
* {@link org.hibernate.tool.schema.Action} enum.
* <p/>
* Interpreted in combination with {@link #HBM2DDL_AUTO}. If no value is specified, the default
* is "none" ({@link org.hibernate.tool.schema.Action#NONE}).
*
* @see org.hibernate.tool.schema.Action
*/
String JAKARTA_HBM2DDL_DATABASE_ACTION = "jakarta.persistence.schema-generation.database.action";
/**
* Setting to perform SchemaManagementTool actions writing the commands into a DDL script file.
* Valid options are defined by the {@link org.hibernate.tool.schema.Action} enum.
* <p/>
* Interpreted in combination with {@link #HBM2DDL_AUTO}. If no value is specified, the default
* is "none" ({@link org.hibernate.tool.schema.Action#NONE}).
*
* @see org.hibernate.tool.schema.Action
*/
String JAKARTA_HBM2DDL_SCRIPTS_ACTION = "jakarta.persistence.schema-generation.scripts.action";
/**
* Allows passing a specific {@link java.sql.Connection} instance to be used by SchemaManagementTool.
* <p/>
* May also be used to determine the values for {@value #HBM2DDL_DB_NAME},
* {@value #HBM2DDL_DB_MAJOR_VERSION} and {@value #HBM2DDL_DB_MINOR_VERSION}.
*/
String JAKARTA_HBM2DDL_CONNECTION = "jakarta.persistence.schema-generation-connection";
/**
* Specifies the name of the database provider in cases where a Connection to the underlying database is
* not available (aka, mainly in generating scripts). In such cases, a value for this setting
* *must* be specified.
* <p/>
* The value of this setting is expected to match the value returned by
* {@link java.sql.DatabaseMetaData#getDatabaseProductName()} for the target database.
* <p/>
* Additionally specifying {@value #HBM2DDL_DB_MAJOR_VERSION} and/or {@value #HBM2DDL_DB_MINOR_VERSION}
* may be required to understand exactly how to generate the required schema commands.
*
* @see #HBM2DDL_DB_MAJOR_VERSION
* @see #HBM2DDL_DB_MINOR_VERSION
*/
@SuppressWarnings("JavaDoc")
String JAKARTA_HBM2DDL_DB_NAME = "jakarta.persistence.database-product-name";
/**
* Specifies the major version of the underlying database, as would be returned by
* {@link java.sql.DatabaseMetaData#getDatabaseMajorVersion} for the target database. This value is used to
* help more precisely determine how to perform schema generation tasks for the underlying database in cases
* where {@value #HBM2DDL_DB_NAME} does not provide enough distinction.
* @see #HBM2DDL_DB_NAME
* @see #HBM2DDL_DB_MINOR_VERSION
*/
String JAKARTA_HBM2DDL_DB_MAJOR_VERSION = "jakarta.persistence.database-major-version";
/**
* Specifies the minor version of the underlying database, as would be returned by
* {@link java.sql.DatabaseMetaData#getDatabaseMinorVersion} for the target database. This value is used to
* help more precisely determine how to perform schema generation tasks for the underlying database in cases
* where the combination of {@value #HBM2DDL_DB_NAME} and {@value #HBM2DDL_DB_MAJOR_VERSION} does not provide
* enough distinction.
*
* @see #HBM2DDL_DB_NAME
* @see #HBM2DDL_DB_MAJOR_VERSION
*/
String JAKARTA_HBM2DDL_DB_MINOR_VERSION = "jakarta.persistence.database-minor-version";
/**
* Specifies whether schema generation commands for schema creation are to be determined based on object/relational
* mapping metadata, DDL scripts, or a combination of the two. See {@link SourceType} for valid set of values.
* If no value is specified, a default is assumed as follows:<ul>
* <li>
* if source scripts are specified (per {@value #HBM2DDL_CREATE_SCRIPT_SOURCE}),then "scripts" is assumed
* </li>
* <li>
* otherwise, "metadata" is assumed
* </li>
* </ul>
*
* @see SourceType
*/
String JAKARTA_HBM2DDL_CREATE_SOURCE = "jakarta.persistence.schema-generation.create-source";
/**
* Specifies whether schema generation commands for schema dropping are to be determined based on object/relational
* mapping metadata, DDL scripts, or a combination of the two. See {@link SourceType} for valid set of values.
* If no value is specified, a default is assumed as follows:<ul>
* <li>
* if source scripts are specified (per {@value #HBM2DDL_DROP_SCRIPT_SOURCE}),then "scripts" is assumed
* </li>
* <li>
* otherwise, "metadata" is assumed
* </li>
* </ul>
*
* @see SourceType
*/
String JAKARTA_HBM2DDL_DROP_SOURCE = "jakarta.persistence.schema-generation.drop-source";
/**
* Specifies the CREATE script file as either a {@link java.io.Reader} configured for reading of the DDL script
* file or a string designating a file {@link java.net.URL} for the DDL script.
* <p/>
* Hibernate historically also accepted {@link #HBM2DDL_IMPORT_FILES} for a similar purpose. This setting
* should be preferred over {@link #HBM2DDL_IMPORT_FILES} moving forward
*
* @see #HBM2DDL_CREATE_SOURCE
* @see #HBM2DDL_IMPORT_FILES
*/
String JAKARTA_HBM2DDL_CREATE_SCRIPT_SOURCE = "jakarta.persistence.schema-generation.create-script-source";
/**
* Specifies the DROP script file as either a {@link java.io.Reader} configured for reading of the DDL script
* file or a string designating a file {@link java.net.URL} for the DDL script.
*
* @see #HBM2DDL_DROP_SOURCE
*/
String JAKARTA_HBM2DDL_DROP_SCRIPT_SOURCE = "jakarta.persistence.schema-generation.drop-script-source";
/**
* For cases where the {@value #HBM2DDL_SCRIPTS_ACTION} value indicates that schema creation commands should
* be written to DDL script file, {@value #HBM2DDL_SCRIPTS_CREATE_TARGET} specifies either a
* {@link java.io.Writer} configured for output of the DDL script or a string specifying the file URL for the DDL
* script.
*
* @see #HBM2DDL_SCRIPTS_ACTION
*/
@SuppressWarnings("JavaDoc")
String JAKARTA_HBM2DDL_SCRIPTS_CREATE_TARGET = "jakarta.persistence.schema-generation.scripts.create-target";
/**
* For cases where the {@value #HBM2DDL_SCRIPTS_ACTION} value indicates that schema drop commands should
* be written to DDL script file, {@value #HBM2DDL_SCRIPTS_DROP_TARGET} specifies either a
* {@link java.io.Writer} configured for output of the DDL script or a string specifying the file URL for the DDL
* script.
*
* @see #HBM2DDL_SCRIPTS_ACTION
*/
@SuppressWarnings("JavaDoc")
String JAKARTA_HBM2DDL_SCRIPTS_DROP_TARGET = "jakarta.persistence.schema-generation.scripts.drop-target";
/**
* JPA variant of {@link #HBM2DDL_IMPORT_FILES}
* <p/>
* Specifies a {@link java.io.Reader} configured for reading of the SQL load script or a string designating the
* file {@link java.net.URL} for the SQL load script.
* <p/>
* A "SQL load script" is a script that performs some database initialization (INSERT, etc).
*/
String JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE = "jakarta.persistence.sql-load-script-source";
/**
* The JPA variant of {@link #HBM2DDL_CREATE_NAMESPACES}
* <p/>
* Specifies whether the persistence provider is to create the database schema(s) in addition to creating
* database objects (tables, sequences, constraints, etc). The value of this boolean property should be set
* to {@code true} if the persistence provider is to create schemas in the database or to generate DDL that
* contains "CREATE SCHEMA" commands. If this property is not supplied (or is explicitly {@code false}), the
* provider should not attempt to create database schemas.
*/
String JAKARTA_HBM2DDL_CREATE_SCHEMAS = "jakarta.persistence.create-database-schemas";
/**
* @deprecated Use {@link #HBM2DDL_CREATE_SCHEMAS} instead: this variable name had a typo.
*/

View File

@ -21,6 +21,7 @@ import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.MappingException;
import org.hibernate.annotations.QueryHints;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.LockModeConverter;
/**
@ -128,6 +129,9 @@ public class QueryHintDefinition {
public Integer getTimeout(String queryName) {
Integer timeout = getInteger( queryName, QueryHints.TIMEOUT_JPA );
if ( timeout == null ) {
timeout = getInteger( queryName, QueryHints.TIMEOUT_JAKARTA_JPA );
}
if ( timeout != null ) {
// convert milliseconds to seconds
@ -142,7 +146,10 @@ public class QueryHintDefinition {
public LockOptions determineLockOptions(NamedQuery namedQueryAnnotation) {
LockModeType lockModeType = namedQueryAnnotation.lockMode();
Integer lockTimeoutHint = getInteger( namedQueryAnnotation.name(), "javax.persistence.lock.timeout" );
Integer lockTimeoutHint = getInteger( namedQueryAnnotation.name(), AvailableSettings.JPA_LOCK_TIMEOUT );
if ( lockTimeoutHint == null ) {
lockTimeoutHint = getInteger( namedQueryAnnotation.name(), AvailableSettings.JAKARTA_JPA_LOCK_TIMEOUT );
}
Boolean followOnLocking = getBoolean( namedQueryAnnotation.name(), QueryHints.FOLLOW_ON_LOCKING );
return determineLockOptions(lockModeType, lockTimeoutHint, followOnLocking);

View File

@ -113,8 +113,14 @@ public class EffectiveEntityGraph implements AppliedGraph, Serializable {
return;
}
final RootGraphImplementor fetchHint = (RootGraphImplementor) properties.get( GraphSemantic.FETCH.getJpaHintName() );
final RootGraphImplementor loadHint = (RootGraphImplementor) properties.get( GraphSemantic.LOAD.getJpaHintName() );
RootGraphImplementor fetchHint = (RootGraphImplementor) properties.get( GraphSemantic.FETCH.getJpaHintName() );
RootGraphImplementor loadHint = (RootGraphImplementor) properties.get( GraphSemantic.LOAD.getJpaHintName() );
if (fetchHint == null) {
fetchHint = (RootGraphImplementor) properties.get( GraphSemantic.FETCH.getJakartaJpaHintName() );
}
if (loadHint == null) {
loadHint = (RootGraphImplementor) properties.get( GraphSemantic.LOAD.getJakartaJpaHintName() );
}
if ( fetchHint == null && loadHint == null ) {
log.debugf( "Neither LOAD nor FETCH graph were found in properties" );

View File

@ -19,7 +19,7 @@ public enum GraphSemantic {
* subsequent select). Attributes that are not specified are treated as
* FetchType.LAZY invariably.
*/
FETCH( "javax.persistence.fetchgraph" ),
FETCH( "javax.persistence.fetchgraph", "jakarta.persistence.fetchgraph" ),
/**
* Indicates a "load graph" EntityGraph. Attributes explicitly specified
@ -28,26 +28,32 @@ public enum GraphSemantic {
* FetchType.LAZY or FetchType.EAGER depending on the attribute's definition
* in metadata.
*/
LOAD( "javax.persistence.loadgraph" );
LOAD( "javax.persistence.loadgraph", "jakarta.persistence.loadgraph" );
private final String jpaHintName;
private final String jakartaJpaHintName;
GraphSemantic(String jpaHintName) {
GraphSemantic(String jpaHintName, String jakartaJpaHintName) {
this.jpaHintName = jpaHintName;
this.jakartaJpaHintName = jakartaJpaHintName;
}
public String getJpaHintName() {
return jpaHintName;
}
public String getJakartaJpaHintName() {
return jakartaJpaHintName;
}
public static GraphSemantic fromJpaHintName(String hintName) {
assert hintName != null;
if ( FETCH.getJpaHintName().equals( hintName ) ) {
if ( FETCH.getJpaHintName().equals( hintName ) || FETCH.getJakartaJpaHintName().equals( hintName ) ) {
return FETCH;
}
if ( LOAD.getJpaHintName().equalsIgnoreCase( hintName ) ) {
if ( LOAD.getJpaHintName().equalsIgnoreCase( hintName ) || LOAD.getJakartaJpaHintName().equalsIgnoreCase( hintName ) ) {
return LOAD;
}

View File

@ -71,6 +71,10 @@ import javax.persistence.CacheRetrieveMode;
import javax.persistence.CacheStoreMode;
import javax.persistence.PessimisticLockScope;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_SHARED_CACHE_STORE_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
@ -277,18 +281,27 @@ public final class FastSessionServices {
//Static defaults:
p.putIfAbsent( AvailableSettings.FLUSH_MODE, FlushMode.AUTO.name() );
p.putIfAbsent( JPA_LOCK_SCOPE, PessimisticLockScope.EXTENDED.name() );
p.putIfAbsent( JAKARTA_JPA_LOCK_SCOPE, PessimisticLockScope.EXTENDED.name() );
p.putIfAbsent( JPA_LOCK_TIMEOUT, LockOptions.WAIT_FOREVER );
p.putIfAbsent( JAKARTA_JPA_LOCK_TIMEOUT, LockOptions.WAIT_FOREVER );
p.putIfAbsent( JPA_SHARED_CACHE_RETRIEVE_MODE, CacheModeHelper.DEFAULT_RETRIEVE_MODE );
p.putIfAbsent( JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE, CacheModeHelper.DEFAULT_RETRIEVE_MODE );
p.putIfAbsent( JPA_SHARED_CACHE_STORE_MODE, CacheModeHelper.DEFAULT_STORE_MODE );
p.putIfAbsent( JAKARTA_JPA_SHARED_CACHE_STORE_MODE, CacheModeHelper.DEFAULT_STORE_MODE );
//Defaults defined by SessionFactory configuration:
final String[] ENTITY_MANAGER_SPECIFIC_PROPERTIES = {
JPA_LOCK_SCOPE,
JAKARTA_JPA_LOCK_SCOPE,
JPA_LOCK_TIMEOUT,
JAKARTA_JPA_LOCK_TIMEOUT,
AvailableSettings.FLUSH_MODE,
JPA_SHARED_CACHE_RETRIEVE_MODE,
JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE,
JPA_SHARED_CACHE_STORE_MODE,
QueryHints.SPEC_HINT_TIMEOUT
JAKARTA_JPA_SHARED_CACHE_STORE_MODE,
QueryHints.SPEC_HINT_TIMEOUT,
QueryHints.JAKARTA_SPEC_HINT_TIMEOUT
};
final Map<String, Object> properties = sf.getProperties();
for ( String key : ENTITY_MANAGER_SPECIFIC_PROPERTIES ) {
@ -328,11 +341,19 @@ public final class FastSessionServices {
}
private static CacheRetrieveMode determineCacheRetrieveMode(Map<String, Object> settings) {
return ( CacheRetrieveMode ) settings.get( JPA_SHARED_CACHE_RETRIEVE_MODE );
final CacheRetrieveMode cacheRetrieveMode = (CacheRetrieveMode) settings.get( JPA_SHARED_CACHE_RETRIEVE_MODE );
if ( cacheRetrieveMode == null ) {
return (CacheRetrieveMode) settings.get( JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE );
}
return cacheRetrieveMode;
}
private static CacheStoreMode determineCacheStoreMode(Map<String, Object> settings) {
return ( CacheStoreMode ) settings.get( JPA_SHARED_CACHE_STORE_MODE );
final CacheStoreMode cacheStoreMode = (CacheStoreMode) settings.get( JPA_SHARED_CACHE_STORE_MODE );
if ( cacheStoreMode == null ) {
return ( CacheStoreMode ) settings.get( JAKARTA_JPA_SHARED_CACHE_STORE_MODE );
}
return cacheStoreMode;
}
public ConnectionObserverStatsBridge getDefaultJdbcObserver() {

View File

@ -234,12 +234,17 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
this.properties = new HashMap<>();
this.properties.putAll( serviceRegistry.getService( ConfigurationService.class ).getSettings() );
if ( !properties.containsKey( AvailableSettings.JPA_VALIDATION_FACTORY ) ) {
if ( !properties.containsKey( AvailableSettings.JPA_VALIDATION_FACTORY )
&& !properties.containsKey( AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY ) ) {
if ( getSessionFactoryOptions().getValidatorFactoryReference() != null ) {
properties.put(
AvailableSettings.JPA_VALIDATION_FACTORY,
getSessionFactoryOptions().getValidatorFactoryReference()
);
properties.put(
AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY,
getSessionFactoryOptions().getValidatorFactoryReference()
);
}
}
@ -1647,6 +1652,8 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
private void maskOutSensitiveInformation(Map<String, Object> props) {
maskOutIfSet( props, AvailableSettings.JPA_JDBC_USER );
maskOutIfSet( props, AvailableSettings.JPA_JDBC_PASSWORD );
maskOutIfSet( props, AvailableSettings.JAKARTA_JPA_JDBC_USER );
maskOutIfSet( props, AvailableSettings.JAKARTA_JPA_JDBC_PASSWORD );
maskOutIfSet( props, AvailableSettings.USER );
maskOutIfSet( props, AvailableSettings.PASS );
}

View File

@ -175,6 +175,10 @@ import org.hibernate.stat.SessionStatistics;
import org.hibernate.stat.internal.SessionStatisticsImpl;
import org.hibernate.stat.spi.StatisticsImplementor;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_SHARED_CACHE_STORE_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
@ -305,8 +309,28 @@ public class SessionImpl
if ( ( queryTimeout = getSessionProperty( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
}
final Object jakartaQueryTimeout;
if ( ( jakartaQueryTimeout = getSessionProperty( QueryHints.JAKARTA_SPEC_HINT_TIMEOUT ) ) != null ) {
query.setHint( QueryHints.JAKARTA_SPEC_HINT_TIMEOUT, jakartaQueryTimeout );
}
final Object lockTimeout;
if ( ( lockTimeout = getSessionProperty( JPA_LOCK_TIMEOUT ) ) != null ) {
final Object jpaLockTimeout = getSessionProperty( JPA_LOCK_TIMEOUT );
if ( jpaLockTimeout == null ) {
lockTimeout = getSessionProperty( JAKARTA_JPA_LOCK_TIMEOUT );
}
else if ( Integer.valueOf( LockOptions.WAIT_FOREVER ).equals( jpaLockTimeout ) ) {
final Object jakartaLockTimeout = getSessionProperty( JAKARTA_JPA_LOCK_TIMEOUT );
if ( jakartaLockTimeout == null ) {
lockTimeout = jpaLockTimeout;
}
else {
lockTimeout = jakartaLockTimeout;
}
}
else {
lockTimeout = jpaLockTimeout;
}
if ( lockTimeout != null ) {
query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
}
}
@ -3424,11 +3448,19 @@ public class SessionImpl
}
private static CacheRetrieveMode determineCacheRetrieveMode(Map<String, Object> settings) {
return ( CacheRetrieveMode ) settings.get( JPA_SHARED_CACHE_RETRIEVE_MODE );
final CacheRetrieveMode cacheRetrieveMode = (CacheRetrieveMode) settings.get( JPA_SHARED_CACHE_RETRIEVE_MODE );
if ( cacheRetrieveMode == null ) {
return (CacheRetrieveMode) settings.get( JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE );
}
return cacheRetrieveMode;
}
private static CacheStoreMode determineCacheStoreMode(Map<String, Object> settings) {
return ( CacheStoreMode ) settings.get( JPA_SHARED_CACHE_STORE_MODE );
final CacheStoreMode cacheStoreMode = (CacheStoreMode) settings.get( JPA_SHARED_CACHE_STORE_MODE );
if ( cacheStoreMode == null ) {
return ( CacheStoreMode ) settings.get( JAKARTA_JPA_SHARED_CACHE_STORE_MODE );
}
return cacheStoreMode;
}
private void checkTransactionNeededForUpdateOperation() {
@ -3574,10 +3606,14 @@ public class SessionImpl
if ( AvailableSettings.FLUSH_MODE.equals( propertyName ) ) {
setHibernateFlushMode( ConfigurationHelper.getFlushMode( value, FlushMode.AUTO ) );
}
else if ( JPA_LOCK_SCOPE.equals( propertyName ) || JPA_LOCK_TIMEOUT.equals( propertyName ) ) {
else if ( JPA_LOCK_SCOPE.equals( propertyName ) || JPA_LOCK_TIMEOUT.equals( propertyName )
|| JAKARTA_JPA_LOCK_SCOPE.equals( propertyName ) || JAKARTA_JPA_LOCK_TIMEOUT.equals( propertyName ) ) {
LockOptionsHelper.applyPropertiesToLockOptions( properties, this::getLockOptionsForWrite );
}
else if ( JPA_SHARED_CACHE_RETRIEVE_MODE.equals( propertyName ) || JPA_SHARED_CACHE_STORE_MODE.equals( propertyName ) ) {
else if ( JPA_SHARED_CACHE_RETRIEVE_MODE.equals( propertyName )
|| JPA_SHARED_CACHE_STORE_MODE.equals( propertyName )
|| JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE.equals( propertyName )
|| JAKARTA_JPA_SHARED_CACHE_STORE_MODE.equals( propertyName ) ) {
getSession().setCacheMode(
CacheModeHelper.interpretCacheMode(
determineCacheStoreMode( properties ),

View File

@ -23,6 +23,7 @@ import static org.hibernate.annotations.QueryHints.NATIVE_SPACES;
import static org.hibernate.annotations.QueryHints.PASS_DISTINCT_THROUGH;
import static org.hibernate.annotations.QueryHints.READ_ONLY;
import static org.hibernate.annotations.QueryHints.TIMEOUT_HIBERNATE;
import static org.hibernate.annotations.QueryHints.TIMEOUT_JAKARTA_JPA;
import static org.hibernate.annotations.QueryHints.TIMEOUT_JPA;
/**
@ -42,6 +43,11 @@ public class QueryHints {
*/
public static final String SPEC_HINT_TIMEOUT = TIMEOUT_JPA;
/**
* The hint key for specifying a query timeout per JPA, which defines the timeout in milliseconds
*/
public static final String JAKARTA_SPEC_HINT_TIMEOUT = TIMEOUT_JAKARTA_JPA;
/**
* The hint key for specifying a comment which is to be embedded into the SQL sent to the database.
*/
@ -100,6 +106,22 @@ public class QueryHints {
*/
public static final String HINT_LOADGRAPH = GraphSemantic.LOAD.getJpaHintName();
/**
* Hint providing a "fetchgraph" EntityGraph. Attributes explicitly specified as AttributeNodes are treated as
* FetchType.EAGER (via join fetch or subsequent select).
*
* Note: Currently, attributes that are not specified are treated as FetchType.LAZY or FetchType.EAGER depending
* on the attribute's definition in metadata, rather than forcing FetchType.LAZY.
*/
public static final String JAKARTA_HINT_FETCHGRAPH = GraphSemantic.FETCH.getJakartaJpaHintName();
/**
* Hint providing a "loadgraph" EntityGraph. Attributes explicitly specified as AttributeNodes are treated as
* FetchType.EAGER (via join fetch or subsequent select). Attributes that are not specified are treated as
* FetchType.LAZY or FetchType.EAGER depending on the attribute's definition in metadata
*/
public static final String JAKARTA_HINT_LOADGRAPH = GraphSemantic.LOAD.getJakartaJpaHintName();
public static final String HINT_FOLLOW_ON_LOCKING = FOLLOW_ON_LOCKING;
public static final String HINT_PASS_DISTINCT_THROUGH = PASS_DISTINCT_THROUGH;
@ -113,6 +135,7 @@ public class QueryHints {
HashSet<String> hints = new HashSet<>();
hints.add( HINT_TIMEOUT );
hints.add( SPEC_HINT_TIMEOUT );
hints.add( JAKARTA_SPEC_HINT_TIMEOUT );
hints.add( HINT_COMMENT );
hints.add( HINT_FETCH_SIZE );
hints.add( HINT_CACHE_REGION );
@ -123,6 +146,8 @@ public class QueryHints {
hints.add( HINT_NATIVE_LOCKMODE );
hints.add( HINT_FETCHGRAPH );
hints.add( HINT_LOADGRAPH );
hints.add( JAKARTA_HINT_FETCHGRAPH );
hints.add( JAKARTA_HINT_LOADGRAPH );
hints.add( HINT_NATIVE_SPACES );
return java.util.Collections.unmodifiableSet( hints );
}

View File

@ -91,6 +91,15 @@ import static org.hibernate.cfg.AvailableSettings.DRIVER;
import static org.hibernate.cfg.AvailableSettings.JACC_CONTEXT_ID;
import static org.hibernate.cfg.AvailableSettings.JACC_ENABLED;
import static org.hibernate.cfg.AvailableSettings.JACC_PREFIX;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_DRIVER;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_PASSWORD;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_URL;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_JDBC_USER;
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_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER;
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_PASSWORD;
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_URL;
@ -259,7 +268,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
metamodelBuilder.getBootstrapContext()
);
withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY ) );
final Object validatorFactory = configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY );
if ( validatorFactory == null ) {
withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY ) );
}
else {
withValidatorFactory( validatorFactory );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// push back class transformation to the environment; for the time being this only has any effect in EE
@ -572,20 +587,30 @@ 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 ) {
mergedSettings.configurationValues.put( JAKARTA_JPA_VALIDATION_MODE, jakartaIntgValidationMode );
}
else if ( persistenceUnit.getValidationMode() != null ) {
mergedSettings.configurationValues.put( JPA_VALIDATION_MODE, persistenceUnit.getValidationMode() );
mergedSettings.configurationValues.put( JAKARTA_JPA_VALIDATION_MODE, persistenceUnit.getValidationMode() );
}
// normalize SharedCacheMode
final Object intgCacheMode = integrationSettingsCopy.remove( JPA_SHARED_CACHE_MODE );
final Object jakartaIntgCacheMode = integrationSettingsCopy.remove( JAKARTA_JPA_SHARED_CACHE_MODE );
if ( intgCacheMode != null ) {
mergedSettings.configurationValues.put( JPA_SHARED_CACHE_MODE, intgCacheMode );
}
else if ( jakartaIntgCacheMode != null ) {
mergedSettings.configurationValues.put( JAKARTA_JPA_SHARED_CACHE_MODE, jakartaIntgCacheMode );
}
else if ( persistenceUnit.getSharedCacheMode() != null ) {
mergedSettings.configurationValues.put( JPA_SHARED_CACHE_MODE, persistenceUnit.getSharedCacheMode() );
mergedSettings.configurationValues.put( JAKARTA_JPA_SHARED_CACHE_MODE, persistenceUnit.getSharedCacheMode() );
}
// Apply all "integration overrides" as the last step. By specification,
@ -618,16 +643,20 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
final Object effectiveUser = NullnessHelper.coalesceSuppliedValues(
() -> integrationSettingsCopy.remove( USER ),
() -> integrationSettingsCopy.remove( JPA_JDBC_USER ),
() -> integrationSettingsCopy.remove( JAKARTA_JPA_JDBC_USER ),
() -> extractPuProperty( persistenceUnit, USER ),
() -> extractPuProperty( persistenceUnit, JPA_JDBC_USER )
() -> extractPuProperty( persistenceUnit, JPA_JDBC_USER ),
() -> extractPuProperty( persistenceUnit, JAKARTA_JPA_JDBC_USER )
);
//noinspection unchecked
final Object effectivePass = NullnessHelper.coalesceSuppliedValues(
() -> integrationSettingsCopy.remove( PASS ),
() -> integrationSettingsCopy.remove( JPA_JDBC_PASSWORD ),
() -> integrationSettingsCopy.remove( JAKARTA_JPA_JDBC_PASSWORD ),
() -> extractPuProperty( persistenceUnit, PASS ),
() -> extractPuProperty( persistenceUnit, JPA_JDBC_PASSWORD )
() -> extractPuProperty( persistenceUnit, JPA_JDBC_PASSWORD ),
() -> extractPuProperty( persistenceUnit, JAKARTA_JPA_JDBC_PASSWORD )
);
if ( effectiveUser != null || effectivePass != null ) {
@ -645,11 +674,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
if ( effectiveUser != null ) {
mergedSettings.configurationValues.put( USER, effectiveUser );
mergedSettings.configurationValues.put( JPA_JDBC_USER, effectiveUser );
mergedSettings.configurationValues.put( JAKARTA_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 );
}
}
@ -662,7 +693,10 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
MergedSettings mergedSettings) {
PersistenceUnitTransactionType txnType = null;
final Object intgTxnType = integrationSettingsCopy.remove( JPA_TRANSACTION_TYPE );
Object intgTxnType = integrationSettingsCopy.remove( JPA_TRANSACTION_TYPE );
if ( intgTxnType == null ) {
intgTxnType = integrationSettingsCopy.remove( JAKARTA_JPA_TRANSACTION_TYPE );
}
if ( intgTxnType != null ) {
txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType( intgTxnType );
@ -671,7 +705,10 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
txnType = persistenceUnit.getTransactionType();
}
else {
final Object puPropTxnType = mergedSettings.configurationValues.get( JPA_TRANSACTION_TYPE );
Object puPropTxnType = mergedSettings.configurationValues.get( JPA_TRANSACTION_TYPE );
if ( puPropTxnType == null ) {
puPropTxnType = mergedSettings.configurationValues.get( JAKARTA_JPA_TRANSACTION_TYPE );
}
if ( puPropTxnType != null ) {
txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType( puPropTxnType );
}
@ -762,6 +799,21 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
if ( integrationSettingsCopy.containsKey( JAKARTA_JPA_JTA_DATASOURCE ) ) {
final Object dataSourceRef = integrationSettingsCopy.remove( JAKARTA_JPA_JTA_DATASOURCE );
if ( dataSourceRef != null ) {
applyDataSource(
dataSourceRef,
true,
integrationSettingsCopy,
mergedSettings
);
// EARLY EXIT!!
return;
}
}
if ( integrationSettingsCopy.containsKey( JPA_NON_JTA_DATASOURCE ) ) {
final Object dataSourceRef = integrationSettingsCopy.remove( JPA_NON_JTA_DATASOURCE );
@ -776,6 +828,20 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
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( URL ) ) {
// these have precedence over the JPA ones
final Object integrationJdbcUrl = integrationSettingsCopy.get( URL );
@ -786,8 +852,10 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
NullnessHelper.coalesceSuppliedValues(
() -> ConfigurationHelper.getString( DRIVER, integrationSettingsCopy ),
() -> ConfigurationHelper.getString( JPA_JDBC_DRIVER, integrationSettingsCopy ),
() -> ConfigurationHelper.getString( JAKARTA_JPA_JDBC_DRIVER, integrationSettingsCopy ),
() -> ConfigurationHelper.getString( DRIVER, mergedSettings.configurationValues ),
() -> ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues )
() -> ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues ),
() -> ConfigurationHelper.getString( JAKARTA_JPA_JDBC_DRIVER, mergedSettings.configurationValues )
),
integrationSettingsCopy,
mergedSettings
@ -818,6 +886,26 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
if ( integrationSettingsCopy.containsKey( JAKARTA_JPA_JDBC_URL ) ) {
final Object integrationJdbcUrl = integrationSettingsCopy.get( JAKARTA_JPA_JDBC_URL );
if ( integrationJdbcUrl != null ) {
//noinspection unchecked
applyJdbcSettings(
integrationJdbcUrl,
NullnessHelper.coalesceSuppliedValues(
() -> ConfigurationHelper.getString( JAKARTA_JPA_JDBC_DRIVER, integrationSettingsCopy ),
() -> ConfigurationHelper.getString( JAKARTA_JPA_JDBC_DRIVER, mergedSettings.configurationValues )
),
integrationSettingsCopy,
mergedSettings
);
// EARLY EXIT!!
return;
}
}
if ( persistenceUnit.getJtaDataSource() != null ) {
applyDataSource(
persistenceUnit.getJtaDataSource(),
@ -874,6 +962,22 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
if ( mergedSettings.configurationValues.containsKey( JAKARTA_JPA_JDBC_URL ) ) {
final Object url = mergedSettings.configurationValues.get( JAKARTA_JPA_JDBC_URL );
if ( url != null && ( ! ( url instanceof String ) || StringHelper.isNotEmpty( (String) url ) ) ) {
applyJdbcSettings(
url,
ConfigurationHelper.getString( JAKARTA_JPA_JDBC_DRIVER, mergedSettings.configurationValues ),
integrationSettingsCopy,
mergedSettings
);
// EARLY EXIT!!
return;
}
}
// any other conditions to account for?
}
@ -894,31 +998,48 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// add to EMF properties (questionable - see HHH-13432)
final String emfKey;
final String inverseEmfKey;
final String jakartaEmfKey;
final String jakartaInverseEmfKey;
if ( isJta ) {
emfKey = JPA_JTA_DATASOURCE;
jakartaEmfKey = JAKARTA_JPA_JTA_DATASOURCE;
inverseEmfKey = JPA_NON_JTA_DATASOURCE;
jakartaInverseEmfKey = JAKARTA_JPA_NON_JTA_DATASOURCE;
}
else {
emfKey = JPA_NON_JTA_DATASOURCE;
jakartaEmfKey = JAKARTA_JPA_NON_JTA_DATASOURCE;
inverseEmfKey = JPA_JTA_DATASOURCE;
jakartaInverseEmfKey = JAKARTA_JPA_JTA_DATASOURCE;
}
mergedSettings.configurationValues.put( emfKey, dataSourceRef );
mergedSettings.configurationValues.put( jakartaEmfKey, dataSourceRef );
// clear any settings logically overridden by this datasource
cleanUpConfigKeys(
integrationSettingsCopy,
mergedSettings,
inverseEmfKey,
jakartaInverseEmfKey,
JPA_JDBC_DRIVER,
JAKARTA_JPA_JDBC_DRIVER,
DRIVER,
JPA_JDBC_URL,
JAKARTA_JPA_JDBC_URL,
URL
);
// clean-up the entries in the "integration overrides" so they do not get get picked
// up in the general "integration overrides" handling
cleanUpConfigKeys( integrationSettingsCopy, DATASOURCE, JPA_JTA_DATASOURCE, JPA_NON_JTA_DATASOURCE );
cleanUpConfigKeys(
integrationSettingsCopy,
DATASOURCE,
JPA_JTA_DATASOURCE,
JAKARTA_JPA_JTA_DATASOURCE,
JPA_NON_JTA_DATASOURCE,
JAKARTA_JPA_NON_JTA_DATASOURCE
);
// add under Hibernate's DATASOURCE setting where the ConnectionProvider will find it
mergedSettings.configurationValues.put( DATASOURCE, dataSourceRef );
@ -952,14 +1073,17 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
MergedSettings mergedSettings) {
mergedSettings.configurationValues.put( URL, url );
mergedSettings.configurationValues.put( JPA_JDBC_URL, url );
mergedSettings.configurationValues.put( JAKARTA_JPA_JDBC_URL, url );
if ( driver != null ) {
mergedSettings.configurationValues.put( DRIVER, driver );
mergedSettings.configurationValues.put( JPA_JDBC_DRIVER, driver );
mergedSettings.configurationValues.put( JAKARTA_JPA_JDBC_DRIVER, driver );
}
else {
mergedSettings.configurationValues.remove( DRIVER );
mergedSettings.configurationValues.remove( JPA_JDBC_DRIVER );
mergedSettings.configurationValues.remove( JAKARTA_JPA_JDBC_DRIVER );
}
// clean up the integration-map values
@ -967,12 +1091,16 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
integrationSettingsCopy,
DRIVER,
JPA_JDBC_DRIVER,
JAKARTA_JPA_JDBC_DRIVER,
URL,
JPA_JDBC_URL,
JAKARTA_JPA_JDBC_URL,
USER,
JPA_JDBC_USER,
JAKARTA_JPA_JDBC_USER,
PASS,
JPA_JDBC_PASSWORD
JPA_JDBC_PASSWORD,
JAKARTA_JPA_JDBC_PASSWORD
);
cleanUpConfigKeys(
@ -980,7 +1108,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
mergedSettings,
DATASOURCE,
JPA_JTA_DATASOURCE,
JPA_NON_JTA_DATASOURCE
JAKARTA_JPA_JTA_DATASOURCE,
JPA_NON_JTA_DATASOURCE,
JAKARTA_JPA_NON_JTA_DATASOURCE
);
}

View File

@ -269,16 +269,29 @@ public class PersistenceXmlParser {
if ( integration.containsKey( AvailableSettings.JPA_PERSISTENCE_PROVIDER ) ) {
persistenceUnit.setProviderClassName( (String) integration.get( AvailableSettings.JPA_PERSISTENCE_PROVIDER ) );
}
else if ( integration.containsKey( AvailableSettings.JAKARTA_JPA_PERSISTENCE_PROVIDER ) ) {
persistenceUnit.setProviderClassName( (String) integration.get( AvailableSettings.JAKARTA_JPA_PERSISTENCE_PROVIDER ) );
}
if ( integration.containsKey( AvailableSettings.JPA_TRANSACTION_TYPE ) ) {
String transactionType = (String) integration.get( AvailableSettings.JPA_TRANSACTION_TYPE );
persistenceUnit.setTransactionType( parseTransactionType( transactionType ) );
}
else if ( integration.containsKey( AvailableSettings.JAKARTA_JPA_TRANSACTION_TYPE ) ) {
String transactionType = (String) integration.get( AvailableSettings.JAKARTA_JPA_TRANSACTION_TYPE );
persistenceUnit.setTransactionType( parseTransactionType( transactionType ) );
}
if ( integration.containsKey( AvailableSettings.JPA_JTA_DATASOURCE ) ) {
persistenceUnit.setJtaDataSource( integration.get( AvailableSettings.JPA_JTA_DATASOURCE ) );
}
else if ( integration.containsKey( AvailableSettings.JAKARTA_JPA_JTA_DATASOURCE ) ) {
persistenceUnit.setJtaDataSource( integration.get( AvailableSettings.JAKARTA_JPA_JTA_DATASOURCE ) );
}
if ( integration.containsKey( AvailableSettings.JPA_NON_JTA_DATASOURCE ) ) {
persistenceUnit.setNonJtaDataSource( integration.get( AvailableSettings.JPA_NON_JTA_DATASOURCE ) );
}
else if ( integration.containsKey( AvailableSettings.JAKARTA_JPA_NON_JTA_DATASOURCE ) ) {
persistenceUnit.setNonJtaDataSource( integration.get( AvailableSettings.JAKARTA_JPA_NON_JTA_DATASOURCE ) );
}
decodeTransactionType( persistenceUnit );

View File

@ -62,7 +62,6 @@ public final class Bootstrap {
String persistenceUnitName,
PersistenceUnitTransactionType transactionType,
Map integration) {
;
return new EntityManagerFactoryBuilderImpl(
PersistenceXmlParser.parse( persistenceXmlUrl, transactionType, integration ).get( persistenceUnitName ),
integration

View File

@ -9,7 +9,6 @@ package org.hibernate.jpa.boot.spi;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.EntityManagerMessageLogger;
import org.hibernate.internal.HEMLogging;
import org.hibernate.jpa.HibernatePersistenceProvider;
@ -100,7 +99,10 @@ public final class ProviderChecker {
if ( integration == null ) {
return null;
}
final String setting = (String) integration.get( AvailableSettings.JPA_PERSISTENCE_PROVIDER );
String setting = (String) integration.get(AvailableSettings.JPA_PERSISTENCE_PROVIDER);
if ( setting == null ) {
setting = (String) integration.get(AvailableSettings.JAKARTA_JPA_PERSISTENCE_PROVIDER);
}
return setting == null ? null : setting.trim();
}

View File

@ -13,6 +13,8 @@ import javax.persistence.PessimisticLockScope;
import org.hibernate.LockOptions;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT;
@ -31,7 +33,12 @@ public final class LockOptionsHelper {
* @param lockOptionsSupplier The reference to the lock to modify
*/
public static void applyPropertiesToLockOptions(final Map<String, Object> props, final Supplier<LockOptions> lockOptionsSupplier) {
Object lockScope = props.get( JPA_LOCK_SCOPE );
String lockScopeHint = JPA_LOCK_SCOPE;
Object lockScope = props.get( lockScopeHint );
if ( lockScope == null ) {
lockScopeHint = JAKARTA_JPA_LOCK_SCOPE;
lockScope = props.get( lockScopeHint );
}
if ( lockScope instanceof String && PessimisticLockScope.valueOf( (String) lockScope ) == PessimisticLockScope.EXTENDED ) {
lockOptionsSupplier.get().setScope( true );
}
@ -40,10 +47,15 @@ public final class LockOptionsHelper {
lockOptionsSupplier.get().setScope( extended );
}
else if ( lockScope != null ) {
throw new PersistenceException( "Unable to parse " + JPA_LOCK_SCOPE + ": " + lockScope );
throw new PersistenceException( "Unable to parse " + lockScopeHint + ": " + lockScope );
}
Object lockTimeout = props.get( JPA_LOCK_TIMEOUT );
String timeoutHint = JPA_LOCK_TIMEOUT;
Object lockTimeout = props.get( timeoutHint );
if (lockTimeout == null) {
timeoutHint = JAKARTA_JPA_LOCK_TIMEOUT;
lockTimeout = props.get( timeoutHint );
}
int timeout = 0;
boolean timeoutSet = false;
if ( lockTimeout instanceof String ) {
@ -55,7 +67,7 @@ public final class LockOptionsHelper {
timeoutSet = true;
}
else if ( lockTimeout != null ) {
throw new PersistenceException( "Unable to parse " + JPA_LOCK_TIMEOUT + ": " + lockTimeout );
throw new PersistenceException( "Unable to parse " + timeoutHint + ": " + lockTimeout );
}
if ( timeoutSet ) {

View File

@ -90,6 +90,10 @@ import org.hibernate.type.Type;
import org.jboss.logging.Logger;
import static org.hibernate.LockOptions.WAIT_FOREVER;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_SHARED_CACHE_STORE_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE;
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
@ -107,6 +111,9 @@ import static org.hibernate.jpa.QueryHints.HINT_LOADGRAPH;
import static org.hibernate.jpa.QueryHints.HINT_NATIVE_SPACES;
import static org.hibernate.jpa.QueryHints.HINT_READONLY;
import static org.hibernate.jpa.QueryHints.HINT_TIMEOUT;
import static org.hibernate.jpa.QueryHints.JAKARTA_HINT_FETCHGRAPH;
import static org.hibernate.jpa.QueryHints.JAKARTA_HINT_LOADGRAPH;
import static org.hibernate.jpa.QueryHints.JAKARTA_SPEC_HINT_TIMEOUT;
import static org.hibernate.jpa.QueryHints.SPEC_HINT_TIMEOUT;
/**
@ -1003,16 +1010,19 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
if ( queryTimeout != null ) {
hints.put( HINT_TIMEOUT, queryTimeout );
hints.put( SPEC_HINT_TIMEOUT, queryTimeout * 1000 );
hints.put( JAKARTA_SPEC_HINT_TIMEOUT, queryTimeout * 1000 );
}
final LockOptions lockOptions = getLockOptions();
final int lockOptionsTimeOut = lockOptions.getTimeOut();
if ( lockOptionsTimeOut != WAIT_FOREVER ) {
hints.put( JPA_LOCK_TIMEOUT, lockOptionsTimeOut );
hints.put( JAKARTA_JPA_LOCK_TIMEOUT, lockOptionsTimeOut );
}
if ( lockOptions.getScope() ) {
hints.put( JPA_LOCK_SCOPE, lockOptions.getScope() );
hints.put( JAKARTA_JPA_LOCK_SCOPE, lockOptions.getScope() );
}
if ( lockOptions.hasAliasSpecificLockModes() && canApplyAliasSpecificLockModeHints() ) {
@ -1031,7 +1041,9 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
if ( cacheStoreMode != null || cacheRetrieveMode != null ) {
putIfNotNull( hints, HINT_CACHE_MODE, CacheModeHelper.interpretCacheMode( cacheStoreMode, cacheRetrieveMode ) );
putIfNotNull( hints, JPA_SHARED_CACHE_RETRIEVE_MODE, cacheRetrieveMode );
putIfNotNull( hints, JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE, cacheRetrieveMode );
putIfNotNull( hints, JPA_SHARED_CACHE_STORE_MODE, cacheStoreMode );
putIfNotNull( hints, JAKARTA_JPA_SHARED_CACHE_STORE_MODE, cacheStoreMode );
}
if ( isCacheable() ) {
@ -1072,12 +1084,12 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
if ( HINT_TIMEOUT.equals( hintName ) ) {
applied = applyTimeoutHint( ConfigurationHelper.getInteger( value ) );
}
else if ( SPEC_HINT_TIMEOUT.equals( hintName ) ) {
else if ( SPEC_HINT_TIMEOUT.equals( hintName ) || JAKARTA_SPEC_HINT_TIMEOUT.equals( hintName ) ) {
// convert milliseconds to seconds
int timeout = (int)Math.round( ConfigurationHelper.getInteger( value ).doubleValue() / 1000.0 );
applied = applyTimeoutHint( timeout );
}
else if ( JPA_LOCK_TIMEOUT.equals( hintName ) ) {
else if ( JPA_LOCK_TIMEOUT.equals( hintName ) || JAKARTA_JPA_LOCK_TIMEOUT.equals( hintName ) ) {
applied = applyLockTimeoutHint( ConfigurationHelper.getInteger( value ) );
}
else if ( HINT_COMMENT.equals( hintName ) ) {
@ -1101,11 +1113,11 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
else if ( HINT_CACHE_MODE.equals( hintName ) ) {
applied = applyCacheModeHint( ConfigurationHelper.getCacheMode( value ) );
}
else if ( JPA_SHARED_CACHE_RETRIEVE_MODE.equals( hintName ) ) {
else if ( JPA_SHARED_CACHE_RETRIEVE_MODE.equals( hintName ) || JAKARTA_JPA_SHARED_CACHE_RETRIEVE_MODE.equals( hintName ) ) {
final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf( value.toString() ) : null;
applied = applyJpaCacheRetrieveMode( retrieveMode );
}
else if ( JPA_SHARED_CACHE_STORE_MODE.equals( hintName ) ) {
else if ( JPA_SHARED_CACHE_STORE_MODE.equals( hintName ) || JAKARTA_JPA_SHARED_CACHE_STORE_MODE.equals( hintName ) ) {
final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf( value.toString() ) : null;
applied = applyJpaCacheStoreMode( storeMode );
}
@ -1133,7 +1145,10 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
applied = false;
}
}
else if ( HINT_FETCHGRAPH.equals( hintName ) || HINT_LOADGRAPH.equals( hintName ) ) {
else if ( HINT_FETCHGRAPH.equals( hintName )
|| HINT_LOADGRAPH.equals( hintName )
|| JAKARTA_HINT_FETCHGRAPH.equals( hintName )
|| JAKARTA_HINT_LOADGRAPH.equals( hintName ) ) {
if ( value instanceof RootGraph ) {
applyGraph( (RootGraph) value, GraphSemantic.fromJpaHintName( hintName ) );
applyEntityGraphQueryHint( new EntityGraphQueryHint( hintName, (RootGraphImpl) value ) );

View File

@ -60,7 +60,10 @@ public class ManagedBeanRegistryInitiator implements StandardServiceInitiator<Ma
// simplified CDI support
final boolean isCdiAvailable = isCdiAvailable( classLoaderService );
final Object beanManagerRef = cfgSvc.getSettings().get( AvailableSettings.CDI_BEAN_MANAGER );
Object beanManagerRef = cfgSvc.getSettings().get( AvailableSettings.CDI_BEAN_MANAGER );
if ( beanManagerRef == null ) {
beanManagerRef = cfgSvc.getSettings().get( AvailableSettings.JAKARTA_CDI_BEAN_MANAGER );
}
if ( beanManagerRef != null ) {
if ( !isCdiAvailable ) {
BeansMessageLogger.BEANS_LOGGER.beanManagerButCdiNotAvailable( beanManagerRef );

View File

@ -111,6 +111,9 @@ public class Helper {
if ( configurationValues.containsKey( AvailableSettings.HBM2DDL_CREATE_SCHEMAS ) ) {
count++;
}
if ( configurationValues.containsKey( AvailableSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS ) ) {
count++;
}
if ( configurationValues.containsKey( AvailableSettings.HBM2DDL_CREATE_NAMESPACES ) ) {
count++;
}
@ -124,15 +127,20 @@ public class Helper {
return ConfigurationHelper.getBoolean(
AvailableSettings.HBM2DDL_CREATE_SCHEMAS,
configurationValues,
//Then try the Hibernate ORM setting:
//Then try the Jakarta JPA setting:
ConfigurationHelper.getBoolean(
AvailableSettings.HBM2DDL_CREATE_NAMESPACES,
AvailableSettings.JAKARTA_HBM2DDL_CREATE_SCHEMAS,
configurationValues,
//And finally fall back to the old name this had before we fixed the typo:
//Then try the Hibernate ORM setting:
ConfigurationHelper.getBoolean(
AvailableSettings.HBM2DLL_CREATE_NAMESPACES,
AvailableSettings.HBM2DDL_CREATE_NAMESPACES,
configurationValues,
false
//And finally fall back to the old name this had before we fixed the typo:
ConfigurationHelper.getBoolean(
AvailableSettings.HBM2DLL_CREATE_NAMESPACES,
configurationValues,
false
)
)
)
);

View File

@ -46,6 +46,7 @@ import org.jboss.logging.Logger;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_CONNECTION;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_DELIMITER;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_CONNECTION;
/**
* The standard Hibernate implementation for performing schema management.
@ -196,12 +197,30 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
if ( providedConnection != null ) {
jdbcContextBuilder.jdbcConnectionAccess = new JdbcConnectionAccessProvidedConnectionImpl( providedConnection );
}
else {
final Connection jakartaProvidedConnection = (Connection) configurationValues.get( JAKARTA_HBM2DDL_CONNECTION );
if ( jakartaProvidedConnection != null ) {
jdbcContextBuilder.jdbcConnectionAccess = new JdbcConnectionAccessProvidedConnectionImpl( jakartaProvidedConnection );
}
}
// see if a specific Dialect override has been provided...
final String explicitDbName = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_NAME );
String dbName = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_NAME );
if ( dbName == null ) {
dbName = (String) configurationValues.get( AvailableSettings.JAKARTA_HBM2DDL_DB_NAME );
}
final String explicitDbName = dbName;
if ( StringHelper.isNotEmpty( explicitDbName ) ) {
final String explicitDbMajor = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_MAJOR_VERSION );
final String explicitDbMinor = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_MINOR_VERSION );
String dbMajor = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_MAJOR_VERSION );
if ( dbMajor == null ) {
dbMajor = (String) configurationValues.get( AvailableSettings.JAKARTA_HBM2DDL_DB_MAJOR_VERSION );
}
String dbMinor = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_MINOR_VERSION );
if ( dbMinor == null ) {
dbMinor = (String) configurationValues.get( AvailableSettings.JAKARTA_HBM2DDL_DB_MINOR_VERSION );
}
final String explicitDbMajor = dbMajor;
final String explicitDbMinor = dbMinor;
final Dialect indicatedDialect = serviceRegistry.getService( DialectResolver.class ).resolveDialect(
new DialectResolutionInfo() {

View File

@ -60,6 +60,7 @@ import org.hibernate.tool.schema.spi.TargetDescriptor;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_CHARSET_NAME;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE;
import static org.hibernate.tool.schema.internal.Helper.interpretScriptSourceSetting;
/**
@ -457,7 +458,10 @@ public class SchemaCreatorImpl implements SchemaCreator {
//final Formatter formatter = format ? DDLFormatterImpl.INSTANCE : FormatStyle.NONE.getFormatter();
final Formatter formatter = FormatStyle.NONE.getFormatter();
final Object importScriptSetting = options.getConfigurationValues().get( HBM2DDL_LOAD_SCRIPT_SOURCE );
Object importScriptSetting = options.getConfigurationValues().get( HBM2DDL_LOAD_SCRIPT_SOURCE );
if ( importScriptSetting == null ) {
importScriptSetting = options.getConfigurationValues().get( JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE );
}
String charsetName = (String) options.getConfigurationValues().get( HBM2DDL_CHARSET_NAME );
if ( importScriptSetting != null ) {

View File

@ -33,6 +33,14 @@ import static org.hibernate.cfg.AvailableSettings.HBM2DDL_DROP_SOURCE;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_SCRIPTS_ACTION;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_SCRIPTS_DROP_TARGET;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_CREATE_SCRIPT_SOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_CREATE_SOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DROP_SCRIPT_SOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DROP_SOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_ACTION;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_CREATE_TARGET;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_DROP_TARGET;
/**
* Responsible for coordinating SchemaManagementTool execution(s) for auto-tooling whether
@ -394,17 +402,29 @@ public class SchemaManagementToolCoordinator {
@Override
public Object getSourceTypeSetting(Map configurationValues) {
return configurationValues.get( HBM2DDL_CREATE_SOURCE );
Object setting = configurationValues.get( HBM2DDL_CREATE_SOURCE );
if ( setting == null ) {
setting = configurationValues.get( JAKARTA_HBM2DDL_CREATE_SOURCE );
}
return setting;
}
@Override
public Object getScriptSourceSetting(Map configurationValues) {
return configurationValues.get( HBM2DDL_CREATE_SCRIPT_SOURCE );
Object setting = configurationValues.get( HBM2DDL_CREATE_SCRIPT_SOURCE );
if ( setting == null ) {
setting = configurationValues.get( JAKARTA_HBM2DDL_CREATE_SCRIPT_SOURCE );
}
return setting;
}
@Override
public Object getScriptTargetSetting(Map configurationValues) {
return configurationValues.get( HBM2DDL_SCRIPTS_CREATE_TARGET );
Object setting = configurationValues.get( HBM2DDL_SCRIPTS_CREATE_TARGET );
if ( setting == null ) {
setting = configurationValues.get( JAKARTA_HBM2DDL_SCRIPTS_CREATE_TARGET );
}
return setting;
}
}
@ -416,17 +436,29 @@ public class SchemaManagementToolCoordinator {
@Override
public Object getSourceTypeSetting(Map configurationValues) {
return configurationValues.get( HBM2DDL_DROP_SOURCE );
Object setting = configurationValues.get( HBM2DDL_DROP_SOURCE );
if ( setting == null ) {
setting = configurationValues.get( JAKARTA_HBM2DDL_DROP_SOURCE );
}
return setting;
}
@Override
public Object getScriptSourceSetting(Map configurationValues) {
return configurationValues.get( HBM2DDL_DROP_SCRIPT_SOURCE );
Object setting = configurationValues.get( HBM2DDL_DROP_SCRIPT_SOURCE );
if ( setting == null ) {
setting = configurationValues.get( JAKARTA_HBM2DDL_DROP_SCRIPT_SOURCE );
}
return setting;
}
@Override
public Object getScriptTargetSetting(Map configurationValues) {
return configurationValues.get( HBM2DDL_SCRIPTS_DROP_TARGET );
Object setting = configurationValues.get( HBM2DDL_SCRIPTS_DROP_TARGET );
if ( setting == null ) {
setting = configurationValues.get( JAKARTA_HBM2DDL_SCRIPTS_DROP_TARGET );
}
return setting;
}
}
@ -454,7 +486,11 @@ public class SchemaManagementToolCoordinator {
@Override
public Object getScriptTargetSetting(Map configurationValues) {
// for now, reuse the CREATE script target setting
return configurationValues.get( HBM2DDL_SCRIPTS_CREATE_TARGET );
Object setting = configurationValues.get( HBM2DDL_SCRIPTS_CREATE_TARGET );
if ( setting == null ) {
setting = configurationValues.get( JAKARTA_HBM2DDL_SCRIPTS_CREATE_TARGET );
}
return setting;
}
}
@ -481,9 +517,17 @@ public class SchemaManagementToolCoordinator {
}
public static ActionGrouping interpret(Map configurationValues) {
Object databaseActionSetting = configurationValues.get( HBM2DDL_DATABASE_ACTION );
Object scriptsActionSetting = configurationValues.get( HBM2DDL_SCRIPTS_ACTION );
if ( databaseActionSetting == null ) {
databaseActionSetting = configurationValues.get( JAKARTA_HBM2DDL_DATABASE_ACTION );
}
if ( scriptsActionSetting == null ) {
scriptsActionSetting = configurationValues.get( JAKARTA_HBM2DDL_SCRIPTS_ACTION );
}
// interpret the JPA settings first
Action databaseAction = Action.interpretJpaSetting( configurationValues.get( HBM2DDL_DATABASE_ACTION ) );
Action scriptAction = Action.interpretJpaSetting( configurationValues.get( HBM2DDL_SCRIPTS_ACTION ) );
Action databaseAction = Action.interpretJpaSetting( databaseActionSetting );
Action scriptAction = Action.interpretJpaSetting( scriptsActionSetting );
// if no JPA settings were specified, look at the legacy HBM2DDL_AUTO setting...
if ( databaseAction == Action.NONE && scriptAction == Action.NONE ) {