Rename JPA copy compliance setting to `hibernate.criteria.copy_tree`
This commit is contained in:
parent
07f3d6727f
commit
5bfbc466eb
|
@ -79,17 +79,6 @@ Traditionally, Hibernate has considered the names locally scoped.
|
||||||
If enabled, the names used by `@TableGenerator` and `@SequenceGenerator` will be considered global so configuring two different generators
|
If enabled, the names used by `@TableGenerator` and `@SequenceGenerator` will be considered global so configuring two different generators
|
||||||
with the same name will cause a `java.lang.IllegalArgumentException` to be thrown at boot time.
|
with the same name will cause a `java.lang.IllegalArgumentException` to be thrown at boot time.
|
||||||
|
|
||||||
`*hibernate.jpa.compliance.criteria_copy*` (e.g. `true` (default value) or `false` )::
|
|
||||||
The Jakarta Persistence spec says that mutations done to `CriteriaQuery`, `CriteriaUpdate` and `CriteriaDelete`
|
|
||||||
after such objects were used to create a `jakarta.persistence.Query` may not affect that query.
|
|
||||||
This requirement makes it necessary to copy these objects because the APIs allow mutations.
|
|
||||||
+
|
|
||||||
If disabled, it is assumed that users do not mutate the criteria query afterwards
|
|
||||||
and due to that, no copy will be created, which will improve performance.
|
|
||||||
+
|
|
||||||
By default, no copies are created to not hurt performance. When enabled,
|
|
||||||
criteria query objects are copied, as required by the JPA specification.
|
|
||||||
|
|
||||||
[[configurations-database-connection]]
|
[[configurations-database-connection]]
|
||||||
=== Database connection properties
|
=== Database connection properties
|
||||||
|
|
||||||
|
@ -509,6 +498,19 @@ The {@link org.hibernate.query.criteria.ValueHandlingMode#INLINE} mode will inli
|
||||||
The default value is {@link org.hibernate.query.criteria.ValueHandlingMode#BIND}.
|
The default value is {@link org.hibernate.query.criteria.ValueHandlingMode#BIND}.
|
||||||
Valid options are defined by the `org.hibernate.query.criteria.ValueHandlingMode` enum.
|
Valid options are defined by the `org.hibernate.query.criteria.ValueHandlingMode` enum.
|
||||||
|
|
||||||
|
`*hibernate.criteria.copy_tree*` (e.g. `true` or `false` (default value) )::
|
||||||
|
The Jakarta Persistence spec says that mutations done to `CriteriaQuery`, `CriteriaUpdate` and `CriteriaDelete`
|
||||||
|
after such objects were used to create a `jakarta.persistence.Query` may not affect that query.
|
||||||
|
This requirement makes it necessary to copy these objects because the APIs allow mutations.
|
||||||
|
+
|
||||||
|
If disabled, it is assumed that users do not mutate the criteria query afterwards
|
||||||
|
and due to that, no copy will be created, which will improve performance.
|
||||||
|
+
|
||||||
|
When bootstrapping Hibernate through the native bootstrap APIs this setting is disabled
|
||||||
|
i.e. no copies are created to not hurt performance.
|
||||||
|
When bootstrapping Hibernate through the JPA SPI this setting is enabled.
|
||||||
|
When enabled, criteria query objects are copied, as required by the Jakarta Persistence specification.
|
||||||
|
|
||||||
`*hibernate.query.fail_on_pagination_over_collection_fetch*` (e.g. `true` or `false` (default value))::
|
`*hibernate.query.fail_on_pagination_over_collection_fetch*` (e.g. `true` or `false` (default value))::
|
||||||
Raises an exception when in-memory pagination over collection fetch is about to be performed.
|
Raises an exception when in-memory pagination over collection fetch is about to be performed.
|
||||||
+
|
+
|
||||||
|
|
|
@ -238,6 +238,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
private boolean connectionProviderDisablesAutoCommit;
|
private boolean connectionProviderDisablesAutoCommit;
|
||||||
private TimeZone jdbcTimeZone;
|
private TimeZone jdbcTimeZone;
|
||||||
private ValueHandlingMode criteriaValueHandlingMode;
|
private ValueHandlingMode criteriaValueHandlingMode;
|
||||||
|
private boolean criteriaCopyTreeEnabled;
|
||||||
private ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode;
|
private ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode;
|
||||||
// These two settings cannot be modified from the builder,
|
// These two settings cannot be modified from the builder,
|
||||||
// in order to maintain consistency.
|
// in order to maintain consistency.
|
||||||
|
@ -534,6 +535,11 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
this.criteriaValueHandlingMode = ValueHandlingMode.interpret(
|
this.criteriaValueHandlingMode = ValueHandlingMode.interpret(
|
||||||
configurationSettings.get( CRITERIA_VALUE_HANDLING_MODE )
|
configurationSettings.get( CRITERIA_VALUE_HANDLING_MODE )
|
||||||
);
|
);
|
||||||
|
this.criteriaCopyTreeEnabled = ConfigurationHelper.getBoolean(
|
||||||
|
AvailableSettings.CRITERIA_COPY_TREE,
|
||||||
|
configurationSettings,
|
||||||
|
jpaBootstrap
|
||||||
|
);
|
||||||
|
|
||||||
// added the boolean parameter in case we want to define some form of "all" as discussed
|
// added the boolean parameter in case we want to define some form of "all" as discussed
|
||||||
this.jpaCompliance = context.getJpaCompliance();
|
this.jpaCompliance = context.getJpaCompliance();
|
||||||
|
@ -1132,6 +1138,11 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
return criteriaValueHandlingMode;
|
return criteriaValueHandlingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCriteriaCopyTreeEnabled() {
|
||||||
|
return criteriaCopyTreeEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableEntityUpdateQueryHandlingMode getImmutableEntityUpdateQueryHandlingMode() {
|
public ImmutableEntityUpdateQueryHandlingMode getImmutableEntityUpdateQueryHandlingMode() {
|
||||||
return immutableEntityUpdateQueryHandlingMode;
|
return immutableEntityUpdateQueryHandlingMode;
|
||||||
|
|
|
@ -378,6 +378,11 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
|
||||||
return delegate.getCriteriaValueHandlingMode();
|
return delegate.getCriteriaValueHandlingMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCriteriaCopyTreeEnabled() {
|
||||||
|
return delegate.isCriteriaCopyTreeEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JpaCompliance getJpaCompliance() {
|
public JpaCompliance getJpaCompliance() {
|
||||||
return delegate.getJpaCompliance();
|
return delegate.getJpaCompliance();
|
||||||
|
|
|
@ -233,10 +233,20 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
|
||||||
|
|
||||||
TimeZone getJdbcTimeZone();
|
TimeZone getJdbcTimeZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.cfg.AvailableSettings#CRITERIA_VALUE_HANDLING_MODE
|
||||||
|
*/
|
||||||
default ValueHandlingMode getCriteriaValueHandlingMode() {
|
default ValueHandlingMode getCriteriaValueHandlingMode() {
|
||||||
return ValueHandlingMode.BIND;
|
return ValueHandlingMode.BIND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.cfg.AvailableSettings#CRITERIA_COPY_TREE
|
||||||
|
*/
|
||||||
|
default boolean isCriteriaCopyTreeEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
JpaCompliance getJpaCompliance();
|
JpaCompliance getJpaCompliance();
|
||||||
|
|
||||||
boolean isFailOnPaginationOverCollectionFetchEnabled();
|
boolean isFailOnPaginationOverCollectionFetchEnabled();
|
||||||
|
|
|
@ -2183,6 +2183,26 @@ public interface AvailableSettings {
|
||||||
*/
|
*/
|
||||||
String CRITERIA_VALUE_HANDLING_MODE = "hibernate.criteria.value_handling_mode";
|
String CRITERIA_VALUE_HANDLING_MODE = "hibernate.criteria.value_handling_mode";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When enabled, specifies that {@linkplain org.hibernate.query.Query queries}
|
||||||
|
* created through {@link jakarta.persistence.EntityManager#createQuery(CriteriaQuery)},
|
||||||
|
* {@link jakarta.persistence.EntityManager#createQuery(CriteriaUpdate)} or
|
||||||
|
* {@link jakarta.persistence.EntityManager#createQuery(CriteriaDelete)}
|
||||||
|
* must create a copy of the passed object such that the resulting {@link jakarta.persistence.Query}
|
||||||
|
* is not affected by any mutations to the original criteria query.
|
||||||
|
* <p>
|
||||||
|
* If disabled, it is assumed that users do not mutate the criteria query afterwards
|
||||||
|
* and due to that, no copy will be created, which will improve performance.
|
||||||
|
* <p>
|
||||||
|
* When bootstrapping Hibernate through the native bootstrap APIs this setting is disabled
|
||||||
|
* i.e. no copies are created to not hurt performance.
|
||||||
|
* When bootstrapping Hibernate through the JPA SPI this setting is enabled.
|
||||||
|
* When enabled, criteria query objects are copied, as required by the Jakarta Persistence specification.
|
||||||
|
*
|
||||||
|
* @since 6.0
|
||||||
|
*/
|
||||||
|
String CRITERIA_COPY_TREE = "hibernate.criteria.copy_tree";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a default value for all {@link org.hibernate.jpa.spi.JpaCompliance}
|
* Specifies a default value for all {@link org.hibernate.jpa.spi.JpaCompliance}
|
||||||
* flags. Each individual flag may still be overridden by explicitly specifying
|
* flags. Each individual flag may still be overridden by explicitly specifying
|
||||||
|
@ -2368,24 +2388,6 @@ public interface AvailableSettings {
|
||||||
*/
|
*/
|
||||||
String JPA_LOAD_BY_ID_COMPLIANCE = "hibernate.jpa.compliance.load_by_id";
|
String JPA_LOAD_BY_ID_COMPLIANCE = "hibernate.jpa.compliance.load_by_id";
|
||||||
|
|
||||||
/**
|
|
||||||
* When enabled, specifies that {@linkplain org.hibernate.query.Query queries}
|
|
||||||
* created through {@link jakarta.persistence.EntityManager#createQuery(CriteriaQuery)},
|
|
||||||
* {@link jakarta.persistence.EntityManager#createQuery(CriteriaUpdate)} or
|
|
||||||
* {@link jakarta.persistence.EntityManager#createQuery(CriteriaDelete)}
|
|
||||||
* must create a copy of the passed object such that the resulting {@link jakarta.persistence.Query}
|
|
||||||
* is not affected by any mutations to the original criteria query.
|
|
||||||
* <p>
|
|
||||||
* If disabled, it is assumed that users do not mutate the criteria query afterwards
|
|
||||||
* and due to that, no copy will be created, which will improve performance.
|
|
||||||
* <p>
|
|
||||||
* By default, no copies are created to not hurt performance. When enabled,
|
|
||||||
* criteria query objects are copied, as required by the JPA specification.
|
|
||||||
*
|
|
||||||
* @since 6.0
|
|
||||||
*/
|
|
||||||
String JPA_CRITERIA_COPY_COMPLIANCE = "hibernate.jpa.compliance.criteria_copy";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the identifier value stored in the database table backing a
|
* Determines if the identifier value stored in the database table backing a
|
||||||
* {@linkplain jakarta.persistence.TableGenerator table generator} is the last
|
* {@linkplain jakarta.persistence.TableGenerator table generator} is the last
|
||||||
|
|
|
@ -210,13 +210,13 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setJpaCriteriaCopyComplianceEnabled(boolean jpaCriteriaCopyComplianceEnabled) {
|
public void setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled) {
|
||||||
delegate.setJpaCriteriaCopyComplianceEnabled( jpaCriteriaCopyComplianceEnabled );
|
delegate.setCriteriaCopyTreeEnabled( jpaCriteriaCopyComplianceEnabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isJpaCriteriaCopyComplianceEnabled() {
|
public boolean isCriteriaCopyTreeEnabled() {
|
||||||
return delegate.isJpaCriteriaCopyComplianceEnabled();
|
return delegate.isCriteriaCopyTreeEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -332,9 +332,9 @@ public interface SharedSessionContractImplementor
|
||||||
|
|
||||||
void setCacheMode(CacheMode cm);
|
void setCacheMode(CacheMode cm);
|
||||||
|
|
||||||
void setJpaCriteriaCopyComplianceEnabled(boolean jpaCriteriaCopyComplianceEnabled);
|
void setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled);
|
||||||
|
|
||||||
boolean isJpaCriteriaCopyComplianceEnabled();
|
boolean isCriteriaCopyTreeEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the flush mode for this session.
|
* Set the flush mode for this session.
|
||||||
|
|
|
@ -143,7 +143,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
private final PhysicalConnectionHandlingMode connectionHandlingMode;
|
private final PhysicalConnectionHandlingMode connectionHandlingMode;
|
||||||
|
|
||||||
private CacheMode cacheMode;
|
private CacheMode cacheMode;
|
||||||
private boolean jpaCriteriaCopyComplianceEnabled;
|
private boolean criteriaCopyTreeEnabled;
|
||||||
|
|
||||||
protected boolean closed;
|
protected boolean closed;
|
||||||
protected boolean waitingForAutoClose;
|
protected boolean waitingForAutoClose;
|
||||||
|
@ -161,7 +161,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.fastSessionServices = factory.getFastSessionServices();
|
this.fastSessionServices = factory.getFastSessionServices();
|
||||||
this.cacheTransactionSync = factory.getCache().getRegionFactory().createTransactionContext( this );
|
this.cacheTransactionSync = factory.getCache().getRegionFactory().createTransactionContext( this );
|
||||||
setJpaCriteriaCopyComplianceEnabled( factory.getJpaMetamodel().getJpaCompliance().isJpaCriteriaCopyComplianceEnabled() );
|
setCriteriaCopyTreeEnabled( factory.getSessionFactoryOptions().isCriteriaCopyTreeEnabled() );
|
||||||
|
|
||||||
this.flushMode = options.getInitialSessionFlushMode();
|
this.flushMode = options.getInitialSessionFlushMode();
|
||||||
|
|
||||||
|
@ -647,13 +647,13 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setJpaCriteriaCopyComplianceEnabled(boolean jpaCriteriaCopyComplianceEnabled) {
|
public void setCriteriaCopyTreeEnabled(boolean jpaCriteriaCopyComplianceEnabled) {
|
||||||
this.jpaCriteriaCopyComplianceEnabled = jpaCriteriaCopyComplianceEnabled;
|
this.criteriaCopyTreeEnabled = jpaCriteriaCopyComplianceEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isJpaCriteriaCopyComplianceEnabled() {
|
public boolean isCriteriaCopyTreeEnabled() {
|
||||||
return jpaCriteriaCopyComplianceEnabled;
|
return criteriaCopyTreeEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -152,7 +152,7 @@ import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_SCOPE;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_TIMEOUT;
|
import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_TIMEOUT;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_RETRIEVE_MODE;
|
import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_RETRIEVE_MODE;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_STORE_MODE;
|
import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_STORE_MODE;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE;
|
import static org.hibernate.cfg.AvailableSettings.CRITERIA_COPY_TREE;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE;
|
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_LOCK_TIMEOUT;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
|
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
|
||||||
|
@ -2600,8 +2600,8 @@ public class SessionImpl
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case JPA_CRITERIA_COPY_COMPLIANCE:
|
case CRITERIA_COPY_TREE:
|
||||||
setJpaCriteriaCopyComplianceEnabled( Boolean.parseBoolean( value.toString() ) );
|
setCriteriaCopyTreeEnabled( Boolean.parseBoolean( value.toString() ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ public class JpaComplianceImpl implements JpaCompliance {
|
||||||
private final boolean closedCompliance;
|
private final boolean closedCompliance;
|
||||||
private final boolean cachingCompliance;
|
private final boolean cachingCompliance;
|
||||||
private final boolean loadByIdCompliance;
|
private final boolean loadByIdCompliance;
|
||||||
private final boolean criteriaCopyCompliance;
|
|
||||||
|
|
||||||
public JpaComplianceImpl(
|
public JpaComplianceImpl(
|
||||||
boolean listCompliance,
|
boolean listCompliance,
|
||||||
|
@ -32,8 +31,7 @@ public class JpaComplianceImpl implements JpaCompliance {
|
||||||
boolean transactionCompliance,
|
boolean transactionCompliance,
|
||||||
boolean closedCompliance,
|
boolean closedCompliance,
|
||||||
boolean cachingCompliance,
|
boolean cachingCompliance,
|
||||||
boolean loadByIdCompliance,
|
boolean loadByIdCompliance) {
|
||||||
boolean criteriaCopyCompliance) {
|
|
||||||
this.queryCompliance = queryCompliance;
|
this.queryCompliance = queryCompliance;
|
||||||
this.transactionCompliance = transactionCompliance;
|
this.transactionCompliance = transactionCompliance;
|
||||||
this.listCompliance = listCompliance;
|
this.listCompliance = listCompliance;
|
||||||
|
@ -43,7 +41,6 @@ public class JpaComplianceImpl implements JpaCompliance {
|
||||||
this.globalGeneratorNameScopeCompliance = globalGeneratorNameScopeCompliance;
|
this.globalGeneratorNameScopeCompliance = globalGeneratorNameScopeCompliance;
|
||||||
this.orderByMappingCompliance = orderByMappingCompliance;
|
this.orderByMappingCompliance = orderByMappingCompliance;
|
||||||
this.loadByIdCompliance = loadByIdCompliance;
|
this.loadByIdCompliance = loadByIdCompliance;
|
||||||
this.criteriaCopyCompliance = criteriaCopyCompliance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,11 +88,6 @@ public class JpaComplianceImpl implements JpaCompliance {
|
||||||
return loadByIdCompliance;
|
return loadByIdCompliance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isJpaCriteriaCopyComplianceEnabled() {
|
|
||||||
return criteriaCopyCompliance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class JpaComplianceBuilder {
|
public static class JpaComplianceBuilder {
|
||||||
private boolean queryCompliance;
|
private boolean queryCompliance;
|
||||||
private boolean listCompliance;
|
private boolean listCompliance;
|
||||||
|
@ -106,7 +98,6 @@ public class JpaComplianceImpl implements JpaCompliance {
|
||||||
private boolean transactionCompliance;
|
private boolean transactionCompliance;
|
||||||
private boolean closedCompliance;
|
private boolean closedCompliance;
|
||||||
private boolean loadByIdCompliance;
|
private boolean loadByIdCompliance;
|
||||||
private boolean criteriaCopyCompliance;
|
|
||||||
|
|
||||||
public JpaComplianceBuilder() {
|
public JpaComplianceBuilder() {
|
||||||
}
|
}
|
||||||
|
@ -156,11 +147,6 @@ public class JpaComplianceImpl implements JpaCompliance {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JpaComplianceBuilder setJpaCriteriaCopyComplianceEnabled(boolean jpaCriteriaCopyComplianceEnabled) {
|
|
||||||
this.criteriaCopyCompliance = jpaCriteriaCopyComplianceEnabled;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
JpaCompliance createJpaCompliance() {
|
JpaCompliance createJpaCompliance() {
|
||||||
return new JpaComplianceImpl(
|
return new JpaComplianceImpl(
|
||||||
listCompliance,
|
listCompliance,
|
||||||
|
@ -171,8 +157,7 @@ public class JpaComplianceImpl implements JpaCompliance {
|
||||||
transactionCompliance,
|
transactionCompliance,
|
||||||
closedCompliance,
|
closedCompliance,
|
||||||
cachingCompliance,
|
cachingCompliance,
|
||||||
loadByIdCompliance,
|
loadByIdCompliance
|
||||||
criteriaCopyCompliance
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class MutableJpaComplianceImpl implements MutableJpaCompliance {
|
||||||
private boolean closedCompliance;
|
private boolean closedCompliance;
|
||||||
private boolean cachingCompliance;
|
private boolean cachingCompliance;
|
||||||
private boolean loadByIdCompliance;
|
private boolean loadByIdCompliance;
|
||||||
private boolean criteriaCopyCompliance;
|
|
||||||
|
|
||||||
public MutableJpaComplianceImpl(Map configurationSettings) {
|
public MutableJpaComplianceImpl(Map configurationSettings) {
|
||||||
this(
|
this(
|
||||||
|
@ -93,12 +92,6 @@ public class MutableJpaComplianceImpl implements MutableJpaCompliance {
|
||||||
configurationSettings,
|
configurationSettings,
|
||||||
jpaByDefault
|
jpaByDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
criteriaCopyCompliance = ConfigurationHelper.getBoolean(
|
|
||||||
AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE,
|
|
||||||
configurationSettings,
|
|
||||||
jpaByDefault
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,11 +139,6 @@ public class MutableJpaComplianceImpl implements MutableJpaCompliance {
|
||||||
return loadByIdCompliance;
|
return loadByIdCompliance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isJpaCriteriaCopyComplianceEnabled() {
|
|
||||||
return criteriaCopyCompliance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Mutators
|
// Mutators
|
||||||
|
|
||||||
|
@ -198,11 +186,6 @@ public class MutableJpaComplianceImpl implements MutableJpaCompliance {
|
||||||
this.loadByIdCompliance = enabled;
|
this.loadByIdCompliance = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setJpaCriteriaCopyComplianceEnabled(boolean jpaCriteriaCopyComplianceEnabled) {
|
|
||||||
this.criteriaCopyCompliance = jpaCriteriaCopyComplianceEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JpaCompliance immutableCopy() {
|
public JpaCompliance immutableCopy() {
|
||||||
JpaComplianceImpl.JpaComplianceBuilder builder = new JpaComplianceImpl.JpaComplianceBuilder();
|
JpaComplianceImpl.JpaComplianceBuilder builder = new JpaComplianceImpl.JpaComplianceBuilder();
|
||||||
|
@ -214,8 +197,7 @@ public class MutableJpaComplianceImpl implements MutableJpaCompliance {
|
||||||
.setTransactionCompliance( transactionCompliance )
|
.setTransactionCompliance( transactionCompliance )
|
||||||
.setClosedCompliance( closedCompliance )
|
.setClosedCompliance( closedCompliance )
|
||||||
.setCachingCompliance( cachingCompliance )
|
.setCachingCompliance( cachingCompliance )
|
||||||
.setLoadByIdCompliance( loadByIdCompliance )
|
.setLoadByIdCompliance( loadByIdCompliance );
|
||||||
.setJpaCriteriaCopyComplianceEnabled( criteriaCopyCompliance );
|
|
||||||
return builder.createJpaCompliance();
|
return builder.createJpaCompliance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,21 +155,4 @@ public interface JpaCompliance {
|
||||||
*/
|
*/
|
||||||
boolean isLoadByIdComplianceEnabled();
|
boolean isLoadByIdComplianceEnabled();
|
||||||
|
|
||||||
/**
|
|
||||||
* JPA says that mutations done to {@link jakarta.persistence.criteria.CriteriaQuery},
|
|
||||||
* {@link jakarta.persistence.criteria.CriteriaUpdate} and {@link jakarta.persistence.criteria.CriteriaDelete}
|
|
||||||
* after such objects were used to create a {@link jakarta.persistence.Query} may not affect that query.
|
|
||||||
* This requirement makes it necessary to copy these objects because the APIs allow mutations.
|
|
||||||
*
|
|
||||||
* If disabled, it is assumed that users do not mutate the criteria query afterwards
|
|
||||||
* and due to that, no copy will be created, which will improve performance.
|
|
||||||
*
|
|
||||||
* By default, no copies are created to not hurt performance. When enabled,
|
|
||||||
* criteria query objects are copied, as required by the JPA specification.
|
|
||||||
*
|
|
||||||
* @see org.hibernate.cfg.AvailableSettings#JPA_CRITERIA_COPY_COMPLIANCE
|
|
||||||
*
|
|
||||||
* @since 6.0
|
|
||||||
*/
|
|
||||||
boolean isJpaCriteriaCopyComplianceEnabled();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,5 @@ public interface MutableJpaCompliance extends JpaCompliance {
|
||||||
|
|
||||||
void setLoadByIdCompliance(boolean enabled);
|
void setLoadByIdCompliance(boolean enabled);
|
||||||
|
|
||||||
void setJpaCriteriaCopyComplianceEnabled(boolean jpaCriteriaCopyComplianceEnabled);
|
|
||||||
|
|
||||||
JpaCompliance immutableCopy();
|
JpaCompliance immutableCopy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,7 +214,7 @@ public class QuerySqmImpl<R>
|
||||||
SharedSessionContractImplementor producer) {
|
SharedSessionContractImplementor producer) {
|
||||||
super( producer );
|
super( producer );
|
||||||
this.hql = CRITERIA_HQL_STRING;
|
this.hql = CRITERIA_HQL_STRING;
|
||||||
if ( producer.isJpaCriteriaCopyComplianceEnabled() ) {
|
if ( producer.isCriteriaCopyTreeEnabled() ) {
|
||||||
this.sqm = criteria.copy( SqmCopyContext.simpleContext() );
|
this.sqm = criteria.copy( SqmCopyContext.simpleContext() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1010,7 +1010,7 @@ public class QuerySqmImpl<R>
|
||||||
public NamedQueryMemento toMemento(String name) {
|
public NamedQueryMemento toMemento(String name) {
|
||||||
if ( CRITERIA_HQL_STRING.equals( getQueryString() ) ) {
|
if ( CRITERIA_HQL_STRING.equals( getQueryString() ) ) {
|
||||||
final SqmStatement sqmStatement ;
|
final SqmStatement sqmStatement ;
|
||||||
if ( !getSession().isJpaCriteriaCopyComplianceEnabled() ) {
|
if ( !getSession().isCriteriaCopyTreeEnabled() ) {
|
||||||
sqmStatement = getSqmStatement().copy( SqmCopyContext.simpleContext() );
|
sqmStatement = getSqmStatement().copy( SqmCopyContext.simpleContext() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -54,7 +54,6 @@ import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||||
import org.hibernate.query.spi.SelectQueryPlan;
|
import org.hibernate.query.spi.SelectQueryPlan;
|
||||||
import org.hibernate.query.sqm.SqmSelectionQuery;
|
import org.hibernate.query.sqm.SqmSelectionQuery;
|
||||||
import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource;
|
import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource;
|
||||||
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
|
|
||||||
import org.hibernate.query.sqm.tree.SqmCopyContext;
|
import org.hibernate.query.sqm.tree.SqmCopyContext;
|
||||||
import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter;
|
import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter;
|
||||||
import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper;
|
import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper;
|
||||||
|
@ -157,7 +156,7 @@ public class SqmSelectionQueryImpl<R> extends AbstractSelectionQuery<R> implemen
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
super( session );
|
super( session );
|
||||||
this.hql = CRITERIA_HQL_STRING;
|
this.hql = CRITERIA_HQL_STRING;
|
||||||
if ( session.isJpaCriteriaCopyComplianceEnabled() ) {
|
if ( session.isCriteriaCopyTreeEnabled() ) {
|
||||||
this.sqm = criteria.copy( SqmCopyContext.simpleContext() );
|
this.sqm = criteria.copy( SqmCopyContext.simpleContext() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -58,9 +58,4 @@ public class JpaComplianceStub implements JpaCompliance {
|
||||||
public boolean isLoadByIdComplianceEnabled() {
|
public boolean isLoadByIdComplianceEnabled() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isJpaCriteriaCopyComplianceEnabled() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@Jpa(
|
@Jpa(
|
||||||
annotatedClasses = CriteriaDeleteTest.Person.class,
|
annotatedClasses = CriteriaDeleteTest.Person.class,
|
||||||
criteriaCopyComplianceEnabled = true
|
jpaComplianceEnabled = true
|
||||||
)
|
)
|
||||||
public class CriteriaDeleteTest {
|
public class CriteriaDeleteTest {
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
properties = {
|
properties = {
|
||||||
@Setting(name = AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE, value = "true"),
|
@Setting(name = AvailableSettings.CRITERIA_COPY_TREE, value = "true"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public class CriteriaMutationQueryTableTest {
|
public class CriteriaMutationQueryTableTest {
|
||||||
|
|
|
@ -43,7 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
properties = {
|
properties = {
|
||||||
@Setting(name = AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE, value = "true"),
|
@Setting(name = AvailableSettings.CRITERIA_COPY_TREE, value = "true"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public class CriteriaMutationQueryWithSecondaryTableTest {
|
public class CriteriaMutationQueryWithSecondaryTableTest {
|
||||||
|
|
|
@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
CriteriaPredicateTest.Deposit.class
|
CriteriaPredicateTest.Deposit.class
|
||||||
},
|
},
|
||||||
properties = {
|
properties = {
|
||||||
@Setting(name = AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE, value = "true"),
|
@Setting(name = AvailableSettings.CRITERIA_COPY_TREE, value = "true"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public class CriteriaPredicateTest {
|
public class CriteriaPredicateTest {
|
||||||
|
|
|
@ -41,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
properties = {
|
properties = {
|
||||||
@Setting(name = AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE, value = "true"),
|
@Setting(name = AvailableSettings.CRITERIA_COPY_TREE, value = "true"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public class JoinTest {
|
public class JoinTest {
|
||||||
|
|
|
@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@Jpa(
|
@Jpa(
|
||||||
annotatedClasses = NamedQueryTest.Person.class,
|
annotatedClasses = NamedQueryTest.Person.class,
|
||||||
properties = @Setting(name = AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE, value = "true")
|
properties = @Setting(name = AvailableSettings.CRITERIA_COPY_TREE, value = "true")
|
||||||
)
|
)
|
||||||
public class NamedQueryTest {
|
public class NamedQueryTest {
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.hibernate.jpa.boot.spi.Bootstrap;
|
||||||
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
||||||
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableMutationStrategy;
|
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableMutationStrategy;
|
||||||
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
|
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
|
||||||
import org.hibernate.resource.jdbc.spi.StatementInspector;
|
|
||||||
import org.hibernate.tool.schema.Action;
|
import org.hibernate.tool.schema.Action;
|
||||||
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
|
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
|
||||||
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.ActionGrouping;
|
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.ActionGrouping;
|
||||||
|
@ -89,6 +88,7 @@ public class EntityManagerFactoryExtension
|
||||||
pui.setExcludeUnlistedClasses( emfAnn.excludeUnlistedClasses() );
|
pui.setExcludeUnlistedClasses( emfAnn.excludeUnlistedClasses() );
|
||||||
|
|
||||||
// JpaCompliance
|
// JpaCompliance
|
||||||
|
pui.getProperties().put( AvailableSettings.JPA_COMPLIANCE, emfAnn.jpaComplianceEnabled() );
|
||||||
pui.getProperties().put( AvailableSettings.JPA_QUERY_COMPLIANCE, emfAnn.queryComplianceEnabled() );
|
pui.getProperties().put( AvailableSettings.JPA_QUERY_COMPLIANCE, emfAnn.queryComplianceEnabled() );
|
||||||
pui.getProperties().put( AvailableSettings.JPA_TRANSACTION_COMPLIANCE, emfAnn.transactionComplianceEnabled() );
|
pui.getProperties().put( AvailableSettings.JPA_TRANSACTION_COMPLIANCE, emfAnn.transactionComplianceEnabled() );
|
||||||
pui.getProperties().put( AvailableSettings.JPA_LIST_COMPLIANCE, emfAnn.listMappingComplianceEnabled() );
|
pui.getProperties().put( AvailableSettings.JPA_LIST_COMPLIANCE, emfAnn.listMappingComplianceEnabled() );
|
||||||
|
@ -98,7 +98,6 @@ public class EntityManagerFactoryExtension
|
||||||
pui.getProperties().put( AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE, emfAnn.generatorScopeComplianceEnabled() );
|
pui.getProperties().put( AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE, emfAnn.generatorScopeComplianceEnabled() );
|
||||||
pui.getProperties().put( AvailableSettings.JPA_ORDER_BY_MAPPING_COMPLIANCE, emfAnn.orderByMappingComplianceEnabled() );
|
pui.getProperties().put( AvailableSettings.JPA_ORDER_BY_MAPPING_COMPLIANCE, emfAnn.orderByMappingComplianceEnabled() );
|
||||||
pui.getProperties().put( AvailableSettings.JPA_LOAD_BY_ID_COMPLIANCE, emfAnn.loadByIdComplianceEnabled() );
|
pui.getProperties().put( AvailableSettings.JPA_LOAD_BY_ID_COMPLIANCE, emfAnn.loadByIdComplianceEnabled() );
|
||||||
pui.getProperties().put( AvailableSettings.JPA_CRITERIA_COPY_COMPLIANCE, emfAnn.criteriaCopyComplianceEnabled() );
|
|
||||||
|
|
||||||
final Setting[] properties = emfAnn.properties();
|
final Setting[] properties = emfAnn.properties();
|
||||||
for ( int i = 0; i < properties.length; i++ ) {
|
for ( int i = 0; i < properties.length; i++ ) {
|
||||||
|
|
|
@ -63,6 +63,11 @@ public @interface Jpa {
|
||||||
SharedCacheMode sharedCacheMode() default SharedCacheMode.UNSPECIFIED;
|
SharedCacheMode sharedCacheMode() default SharedCacheMode.UNSPECIFIED;
|
||||||
ValidationMode validationMode() default ValidationMode.NONE;
|
ValidationMode validationMode() default ValidationMode.NONE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.cfg.AvailableSettings#JPA_COMPLIANCE
|
||||||
|
*/
|
||||||
|
boolean jpaComplianceEnabled() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see JpaCompliance#isJpaQueryComplianceEnabled()
|
* @see JpaCompliance#isJpaQueryComplianceEnabled()
|
||||||
*/
|
*/
|
||||||
|
@ -109,11 +114,6 @@ public @interface Jpa {
|
||||||
*/
|
*/
|
||||||
boolean loadByIdComplianceEnabled() default false;
|
boolean loadByIdComplianceEnabled() default false;
|
||||||
|
|
||||||
/**
|
|
||||||
* @see JpaCompliance#isLoadByIdComplianceEnabled()
|
|
||||||
*/
|
|
||||||
boolean criteriaCopyComplianceEnabled() default false;
|
|
||||||
|
|
||||||
boolean excludeUnlistedClasses() default false;
|
boolean excludeUnlistedClasses() default false;
|
||||||
|
|
||||||
StandardDomainModel[] standardModels() default {};
|
StandardDomainModel[] standardModels() default {};
|
||||||
|
|
|
@ -318,15 +318,15 @@ todo (6.0) - cover bulk manipulation query handling
|
||||||
|
|
||||||
|
|
||||||
[[query-criteria-copy]]
|
[[query-criteria-copy]]
|
||||||
== JPA Criteria behavior change
|
== Hibernate Criteria behavior change
|
||||||
|
|
||||||
Without JPA compliance (`hibernate.jpa.compliance`) or when the newly introduced `hibernate.jpa.compliance.criteria_copy` configuration property
|
By default, when bootstrapping Hibernate through the native bootstrap APIs or when explicitly disabling the newly introduced
|
||||||
is disabled, it is expected that criteria queries passed to `jakarta.persistence.EntityManager#createQuery(CriteriaQuery)`,
|
`hibernate.criteria.copy_tree` configuration property, it is expected that criteria queries passed to
|
||||||
`jakarta.persistence.EntityManager#createQuery(CriteriaUpdate)` or `jakarta.persistence.EntityManager#createQuery(CriteriaDelete)`
|
`jakarta.persistence.EntityManager#createQuery(CriteriaQuery)`, `jakarta.persistence.EntityManager#createQuery(CriteriaUpdate)`
|
||||||
are not mutated afterwards to avoid the need for copying the criteria query.
|
or `jakarta.persistence.EntityManager#createQuery(CriteriaDelete)` are not mutated afterwards to avoid the need for copying the criteria query.
|
||||||
|
|
||||||
Prior to 6.0, mutations to criteria queries didn't affect `Query` instances created from that.
|
Prior to 6.0, mutations to criteria queries didn't affect `Query` instances created from that.
|
||||||
To retain backwards compatibility, enable the `hibernate.jpa.compliance.criteria_copy` configuration property.
|
To retain backwards compatibility, enable the `hibernate.criteria.copy_tree` configuration property.
|
||||||
|
|
||||||
[[query-sqm-rows]]
|
[[query-sqm-rows]]
|
||||||
==== Result "rows"
|
==== Result "rows"
|
||||||
|
|
Loading…
Reference in New Issue