api, spi, internal, deprecation

org.hibernate.query package
This commit is contained in:
Steve Ebersole 2022-01-21 07:48:25 -06:00
parent 2b5a5fc196
commit 8cda382ef9
31 changed files with 385 additions and 268 deletions

View File

@ -9,6 +9,19 @@ package org.hibernate.userguide.caching;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.CacheMode;
import org.hibernate.Session;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NaturalId;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.stat.CacheRegionStatistics;
import org.hibernate.stat.Statistics;
import org.junit.Ignore;
import org.junit.Test;
import jakarta.persistence.CacheRetrieveMode;
import jakarta.persistence.CacheStoreMode;
import jakarta.persistence.Cacheable;
@ -18,19 +31,8 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import org.hibernate.CacheMode;
import org.hibernate.Session;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NaturalId;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.QueryHints;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.stat.CacheRegionStatistics;
import org.hibernate.stat.Statistics;
import org.junit.Ignore;
import org.junit.Test;
import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE;
import static org.hibernate.jpa.HibernateHints.HINT_CACHE_REGION;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertNotNull;
@ -131,8 +133,8 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
"from Person p " +
"where p.id > :id", Person.class)
.setParameter("id", 0L)
.setHint(QueryHints.HINT_CACHEABLE, "true")
.setHint(QueryHints.HINT_CACHE_REGION, "query.cache.person")
.setHint(HINT_CACHEABLE, "true")
.setHint(HINT_CACHE_REGION, "query.cache.person")
.getResultList();
//end::caching-query-region-jpa-example[]
});
@ -159,8 +161,8 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
"from Person p " +
"where p.id > :id", Person.class)
.setParameter("id", 0L)
.setHint(QueryHints.HINT_CACHEABLE, "true")
.setHint(QueryHints.HINT_CACHE_REGION, "query.cache.person")
.setHint(HINT_CACHEABLE, "true")
.setHint(HINT_CACHE_REGION, "query.cache.person")
.setHint("jakarta.persistence.cache.storeMode", CacheStoreMode.REFRESH)
.getResultList();
//end::caching-query-region-store-mode-jpa-example[]
@ -223,7 +225,7 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
//tag::caching-management-cache-mode-query-jpa-example[]
List<Person> persons = entityManager.createQuery(
"select p from Person p", Person.class)
.setHint(QueryHints.HINT_CACHEABLE, "true")
.setHint(HINT_CACHEABLE, "true")
.setHint("jakarta.persistence.cache.retrieveMode" , CacheRetrieveMode.USE)
.setHint("jakarta.persistence.cache.storeMode" , CacheStoreMode.REFRESH)
.getResultList();

View File

@ -68,9 +68,9 @@ public class QueryHints implements HibernateHints, SpecHints {
public static final String TIMEOUT_HIBERNATE = HibernateHints.HINT_TIMEOUT;
/**
* @see org.hibernate.jpa.SpecHints#HINT_QUERY_TIMEOUT
* @see org.hibernate.jpa.SpecHints#HINT_SPEC_QUERY_TIMEOUT
*/
public static final String TIMEOUT_JAKARTA_JPA = SpecHints.HINT_QUERY_TIMEOUT;
public static final String TIMEOUT_JAKARTA_JPA = SpecHints.HINT_SPEC_QUERY_TIMEOUT;
/**
* @see HibernateHints#HINT_NATIVE_LOCK_MODE
@ -99,7 +99,7 @@ public class QueryHints implements HibernateHints, SpecHints {
public static final String CALLABLE_FUNCTION = HibernateHints.HINT_CALLABLE_FUNCTION;
/**
* @see org.hibernate.jpa.SpecHints#HINT_QUERY_TIMEOUT
* @see org.hibernate.jpa.SpecHints#HINT_SPEC_QUERY_TIMEOUT
*/
public static final String TIMEOUT_JPA = LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT;
}

View File

@ -100,14 +100,14 @@ public interface AvailableSettings {
String JAKARTA_SHARED_CACHE_MODE = "jakarta.persistence.sharedCache.mode";
/**
* @see org.hibernate.jpa.SpecHints#HINT_CACHE_RETRIEVE_MODE
* @see org.hibernate.jpa.SpecHints#HINT_SPEC_CACHE_RETRIEVE_MODE
*/
String JAKARTA_SHARED_CACHE_RETRIEVE_MODE = org.hibernate.jpa.SpecHints.HINT_CACHE_RETRIEVE_MODE;
String JAKARTA_SHARED_CACHE_RETRIEVE_MODE = org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE;
/**
* @see org.hibernate.jpa.SpecHints#HINT_CACHE_STORE_MODE
* @see org.hibernate.jpa.SpecHints#HINT_SPEC_CACHE_STORE_MODE
*/
String JAKARTA_SHARED_CACHE_STORE_MODE = org.hibernate.jpa.SpecHints.HINT_CACHE_STORE_MODE;
String JAKARTA_SHARED_CACHE_STORE_MODE = org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_STORE_MODE;
/**
* Used to indicate what form of automatic validation is in effect as per rules defined
@ -349,7 +349,7 @@ public interface AvailableSettings {
String DIALECT ="hibernate.dialect";
/**
* Specifies additional {@link org.hibernate.engine.jdbc.dialect.spi.DialectResolver} implementations
* Specifies additional {@link org.hibernate.engine.jdbc.dialect.spi.DialectResolver} implementations
* to register with the standard {@link org.hibernate.engine.jdbc.dialect.spi.DialectFactory}.
*/
String DIALECT_RESOLVERS = "hibernate.dialect_resolvers";

View File

@ -83,7 +83,7 @@ public class QueryHintDefinition {
// Specialized access
public Integer getTimeout() {
final Integer jakartaTimeout = getInteger( SpecHints.HINT_QUERY_TIMEOUT );
final Integer jakartaTimeout = getInteger( SpecHints.HINT_SPEC_QUERY_TIMEOUT );
if ( jakartaTimeout != null ) {
// convert milliseconds to seconds
return (int) Math.round( jakartaTimeout.doubleValue() / 1000.0 );

View File

@ -8,8 +8,8 @@ package org.hibernate.graph;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOAD_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_LOAD_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
/**
* JPA specifies two distinct ways to apply an {@link jakarta.persistence.EntityGraph} -
@ -27,7 +27,7 @@ public enum GraphSemantic {
* are not fetched.
* </ul>
*/
FETCH( HINT_FETCH_GRAPH, HINT_JAVAEE_FETCH_GRAPH ),
FETCH( HINT_SPEC_FETCH_GRAPH, HINT_JAVAEE_FETCH_GRAPH ),
/**
* Indicates that an {@link jakarta.persistence.EntityGraph} should be interpreted as a JPA "load graph".
@ -38,7 +38,7 @@ public enum GraphSemantic {
* depending on the mapping of the attribute, instead of forcing {@code FetchType.LAZY}.
* </ul>
*/
LOAD( HINT_LOAD_GRAPH, HINT_JAVAEE_LOAD_GRAPH );
LOAD( HINT_SPEC_LOAD_GRAPH, HINT_JAVAEE_LOAD_GRAPH );
private final String jakartaHintName;
private final String jpaHintName;

View File

@ -62,7 +62,6 @@ import org.hibernate.event.spi.ReplicateEventListener;
import org.hibernate.event.spi.ResolveNaturalIdEventListener;
import org.hibernate.event.spi.SaveOrUpdateEventListener;
import org.hibernate.jpa.LegacySpecHints;
import org.hibernate.jpa.QueryHints;
import org.hibernate.jpa.SpecHints;
import org.hibernate.jpa.internal.util.CacheModeHelper;
import org.hibernate.jpa.internal.util.ConfigurationHelper;
@ -289,11 +288,11 @@ public final class FastSessionServices {
//Defaults defined by SessionFactory configuration:
final String[] ENTITY_MANAGER_SPECIFIC_PROPERTIES = {
SpecHints.HINT_LOCK_SCOPE,
SpecHints.HINT_LOCK_TIMEOUT,
SpecHints.HINT_QUERY_TIMEOUT,
SpecHints.HINT_CACHE_RETRIEVE_MODE,
SpecHints.HINT_CACHE_STORE_MODE,
SpecHints.HINT_SPEC_LOCK_SCOPE,
SpecHints.HINT_SPEC_LOCK_TIMEOUT,
SpecHints.HINT_SPEC_QUERY_TIMEOUT,
SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE,
SpecHints.HINT_SPEC_CACHE_STORE_MODE,
AvailableSettings.FLUSH_MODE,

View File

@ -103,7 +103,7 @@ import org.hibernate.graph.GraphSemantic;
import org.hibernate.graph.internal.RootGraphImpl;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.internal.util.ExceptionHelper;
import org.hibernate.jpa.QueryHints;
import org.hibernate.jpa.internal.LegacySpecHelper;
import org.hibernate.jpa.internal.util.CacheModeHelper;
import org.hibernate.jpa.internal.util.ConfigurationHelper;
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
@ -149,6 +149,11 @@ 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;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE;
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOCK_TIMEOUT;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
/**
* Concrete implementation of a the {@link Session} API.
@ -285,33 +290,26 @@ public class SessionImpl
if ( lockOptionsForRead.getLockMode() != LockMode.NONE ) {
query.setLockMode( getLockMode( lockOptionsForRead.getLockMode() ) );
}
final Object queryTimeout;
if ( ( queryTimeout = getSessionProperty( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
final Object specQueryTimeout = LegacySpecHelper.getInteger(
HINT_SPEC_QUERY_TIMEOUT,
HINT_JAVAEE_QUERY_TIMEOUT,
this::getSessionProperty
);
if ( specQueryTimeout != null ) {
query.setHint( HINT_SPEC_QUERY_TIMEOUT, specQueryTimeout );
query.setHint( HINT_JAVAEE_QUERY_TIMEOUT, specQueryTimeout );
}
final Object jakartaQueryTimeout;
if ( ( jakartaQueryTimeout = getSessionProperty( QueryHints.JAKARTA_SPEC_HINT_TIMEOUT ) ) != null ) {
query.setHint( QueryHints.JAKARTA_SPEC_HINT_TIMEOUT, jakartaQueryTimeout );
}
final Object lockTimeout;
final Object jpaLockTimeout = getSessionProperty( JPA_LOCK_TIMEOUT );
if ( jpaLockTimeout == null ) {
lockTimeout = getSessionProperty( JAKARTA_LOCK_TIMEOUT );
}
else if ( Integer.valueOf( LockOptions.WAIT_FOREVER ).equals( jpaLockTimeout ) ) {
final Object jakartaLockTimeout = getSessionProperty( JAKARTA_LOCK_TIMEOUT );
if ( jakartaLockTimeout == null ) {
lockTimeout = jpaLockTimeout;
}
else {
lockTimeout = jakartaLockTimeout;
}
}
else {
lockTimeout = jpaLockTimeout;
}
if ( lockTimeout != null ) {
query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
final Integer specLockTimeout = LegacySpecHelper.getInteger(
HINT_SPEC_LOCK_TIMEOUT,
HINT_JAVAEE_LOCK_TIMEOUT,
this::getSessionProperty,
(value) -> Integer.valueOf( LockOptions.WAIT_FOREVER ).equals( value )
);
if ( specLockTimeout != null ) {
query.setHint( HINT_SPEC_LOCK_TIMEOUT, specLockTimeout );
query.setHint( HINT_JAVAEE_LOCK_TIMEOUT, specLockTimeout );
}
}
@ -2269,7 +2267,7 @@ public class SessionImpl
try {
getLoadQueryInfluencers().getEffectiveEntityGraph().applyConfiguredGraph( properties );
Boolean readOnly = properties == null ? null : (Boolean) properties.get( QueryHints.HINT_READONLY );
Boolean readOnly = properties == null ? null : (Boolean) properties.get( HINT_READ_ONLY );
getLoadQueryInfluencers().setReadOnly( readOnly );
final IdentifierLoadAccess<T> loadAccess = byId( entityClass );
loadAccess.with( determineAppropriateLocalCacheMode( properties ) );

View File

@ -6,7 +6,9 @@
*/
package org.hibernate.jpa;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import jakarta.persistence.LockModeType;
@ -21,5 +23,37 @@ import jakarta.persistence.LockModeType;
*
* @author Steve Ebersole
*/
public interface AvailableHints extends HibernateHints, SpecHints {
public class AvailableHints implements HibernateHints, SpecHints {
private static final Set<String> HINTS = buildHintsSet();
public static Set<String> getDefinedHints() {
return HINTS;
}
private static Set<String> buildHintsSet() {
final HashSet<String> hints = new HashSet<>();
hints.add( HibernateHints.HINT_TIMEOUT );
hints.add( HibernateHints.HINT_READ_ONLY );
hints.add( HibernateHints.HINT_FLUSH_MODE );
hints.add( HibernateHints.HINT_CACHEABLE );
hints.add( HibernateHints.HINT_CACHE_MODE );
hints.add( HibernateHints.HINT_CACHE_REGION );
hints.add( HibernateHints.HINT_FETCH_SIZE );
hints.add( HibernateHints.HINT_COMMENT );
hints.add( HibernateHints.HINT_NATIVE_SPACES );
hints.add( HibernateHints.HINT_NATIVE_LOCK_MODE );
hints.add( SpecHints.HINT_SPEC_QUERY_TIMEOUT );
hints.add( SpecHints.HINT_SPEC_FETCH_GRAPH );
hints.add( SpecHints.HINT_SPEC_LOAD_GRAPH );
hints.add( LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT );
hints.add( LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH );
hints.add( LegacySpecHints.HINT_JAVAEE_LOAD_GRAPH );
return java.util.Collections.unmodifiableSet( hints );
}
}

View File

@ -23,37 +23,37 @@ package org.hibernate.jpa;
@Deprecated
public interface LegacySpecHints {
/**
* @see SpecHints#HINT_FETCH_GRAPH
* @see SpecHints#HINT_SPEC_FETCH_GRAPH
*/
String HINT_JAVAEE_FETCH_GRAPH = "javax.persistence.fetchgraph";
/**
* @see SpecHints#HINT_LOAD_GRAPH
* @see SpecHints#HINT_SPEC_LOAD_GRAPH
*/
String HINT_JAVAEE_LOAD_GRAPH = "javax.persistence.loadgraph";
/**
* @see SpecHints#HINT_LOCK_TIMEOUT
* @see SpecHints#HINT_SPEC_LOCK_TIMEOUT
*/
String HINT_JAVAEE_LOCK_TIMEOUT = "javax.persistence.lock.timeout";
/**
* @see SpecHints#HINT_LOCK_SCOPE
* @see SpecHints#HINT_SPEC_LOCK_SCOPE
*/
String HINT_JAVAEE_LOCK_SCOPE = "javax.persistence.lock.scope";
/**
* @see SpecHints#HINT_QUERY_TIMEOUT
* @see SpecHints#HINT_SPEC_QUERY_TIMEOUT
*/
String HINT_JAVAEE_QUERY_TIMEOUT = "javax.persistence.query.timeout";
/**
* @see SpecHints#HINT_CACHE_RETRIEVE_MODE
* @see SpecHints#HINT_SPEC_CACHE_RETRIEVE_MODE
*/
String HINT_JAVAEE_CACHE_RETRIEVE_MODE = "javax.persistence.cache.retrieveMode";
/**
* @see SpecHints#HINT_CACHE_STORE_MODE
* @see SpecHints#HINT_SPEC_CACHE_STORE_MODE
*/
String HINT_JAVAEE_CACHE_STORE_MODE = "javax.persistence.cache.storeMode";
}

View File

@ -17,9 +17,9 @@ import java.util.Set;
*/
public class QueryHints {
/**
* @see SpecHints#HINT_QUERY_TIMEOUT
* @see SpecHints#HINT_SPEC_QUERY_TIMEOUT
*/
public static final String JAKARTA_SPEC_HINT_TIMEOUT = SpecHints.HINT_QUERY_TIMEOUT;
public static final String JAKARTA_SPEC_HINT_TIMEOUT = SpecHints.HINT_SPEC_QUERY_TIMEOUT;
/**
* @see HibernateHints#HINT_COMMENT
@ -62,24 +62,24 @@ public class QueryHints {
public static final String HINT_NATIVE_LOCKMODE = HibernateHints.HINT_NATIVE_LOCK_MODE;
/**
* @see SpecHints#HINT_FETCH_GRAPH
* @see SpecHints#HINT_SPEC_FETCH_GRAPH
*/
public static final String JAKARTA_HINT_FETCH_GRAPH = SpecHints.HINT_FETCH_GRAPH;
public static final String JAKARTA_HINT_FETCH_GRAPH = SpecHints.HINT_SPEC_FETCH_GRAPH;
/**
* @see SpecHints#HINT_LOAD_GRAPH
* @see SpecHints#HINT_SPEC_LOAD_GRAPH
*/
public static final String JAKARTA_HINT_FETCHGRAPH = SpecHints.HINT_FETCH_GRAPH;
public static final String JAKARTA_HINT_FETCHGRAPH = SpecHints.HINT_SPEC_FETCH_GRAPH;
/**
* @see SpecHints#HINT_LOAD_GRAPH
* @see SpecHints#HINT_SPEC_LOAD_GRAPH
*/
public static final String JAKARTA_HINT_LOAD_GRAPH = SpecHints.HINT_LOAD_GRAPH;
public static final String JAKARTA_HINT_LOAD_GRAPH = SpecHints.HINT_SPEC_LOAD_GRAPH;
/**
* @see SpecHints#HINT_LOAD_GRAPH
* @see SpecHints#HINT_SPEC_LOAD_GRAPH
*/
public static final String JAKARTA_HINT_LOADGRAPH = SpecHints.HINT_LOAD_GRAPH;
public static final String JAKARTA_HINT_LOADGRAPH = SpecHints.HINT_SPEC_LOAD_GRAPH;
/**
* @see HibernateHints#HINT_FOLLOW_ON_LOCKING
@ -104,17 +104,13 @@ public class QueryHints {
/**
* The hint key for specifying a query timeout per Hibernate O/RM, which defines the timeout in seconds.
*
* @deprecated use {@link #SPEC_HINT_TIMEOUT} instead
* @see HibernateHints#HINT_TIMEOUT
*/
@Deprecated
public static final String HINT_TIMEOUT = HibernateHints.HINT_TIMEOUT;
/**
* @see LegacySpecHints#HINT_JAVAEE_QUERY_TIMEOUT
*
* @deprecated use {@link SpecHints#HINT_QUERY_TIMEOUT} instead
*/
@Deprecated
public static final String SPEC_HINT_TIMEOUT = LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT;
@ -134,9 +130,9 @@ public class QueryHints {
hints.add( HibernateHints.HINT_NATIVE_SPACES );
hints.add( HibernateHints.HINT_NATIVE_LOCK_MODE );
hints.add( SpecHints.HINT_QUERY_TIMEOUT );
hints.add( SpecHints.HINT_FETCH_GRAPH );
hints.add( SpecHints.HINT_LOAD_GRAPH );
hints.add( SpecHints.HINT_SPEC_QUERY_TIMEOUT );
hints.add( SpecHints.HINT_SPEC_FETCH_GRAPH );
hints.add( SpecHints.HINT_SPEC_LOAD_GRAPH );
hints.add( LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT );
hints.add( LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH );

View File

@ -8,7 +8,6 @@ package org.hibernate.jpa;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.graph.GraphSemantic;
import jakarta.persistence.LockModeType;
@ -31,7 +30,7 @@ public interface SpecHints {
*
* @see GraphSemantic#FETCH
*/
String HINT_FETCH_GRAPH = "jakarta.persistence.fetchgraph";
String HINT_SPEC_FETCH_GRAPH = "jakarta.persistence.fetchgraph";
/**
* Hint providing a {@link jakarta.persistence.EntityGraph} which should be
@ -39,19 +38,19 @@ public interface SpecHints {
*
* @see GraphSemantic#LOAD
*/
String HINT_LOAD_GRAPH = "jakarta.persistence.loadgraph";
String HINT_SPEC_LOAD_GRAPH = "jakarta.persistence.loadgraph";
/**
* Hint requesting a pessimistic lock timeout (in milliseconds).
*/
String HINT_LOCK_TIMEOUT = "jakarta.persistence.lock.timeout";
String HINT_SPEC_LOCK_TIMEOUT = "jakarta.persistence.lock.timeout";
/**
* Hint indicating whether to extend pessimistic locking to
* associated tables. Expected to be an instance of
* {@link jakarta.persistence.PessimisticLockScope}
*/
String HINT_LOCK_SCOPE = "jakarta.persistence.lock.scope";
String HINT_SPEC_LOCK_SCOPE = "jakarta.persistence.lock.scope";
/**
* The Jakarta Persistence defined hint for requesting a timeout
@ -59,7 +58,7 @@ public interface SpecHints {
*
* @implSpec Not valid for load and/or lock operations
*/
String HINT_QUERY_TIMEOUT = "jakarta.persistence.query.timeout";
String HINT_SPEC_QUERY_TIMEOUT = "jakarta.persistence.query.timeout";
/**
* Hint specifying how Hibernate should handle retrieving data from
@ -70,7 +69,7 @@ public interface SpecHints {
* @see jakarta.persistence.Query#setHint
* @see org.hibernate.CacheMode
*/
String HINT_CACHE_RETRIEVE_MODE = "jakarta.persistence.cache.retrieveMode";
String HINT_SPEC_CACHE_RETRIEVE_MODE = "jakarta.persistence.cache.retrieveMode";
/**
* Hint specifying how Hibernate should handle retrieving data from
@ -81,6 +80,6 @@ public interface SpecHints {
* @see jakarta.persistence.Query#setHint
* @see org.hibernate.CacheMode
*/
String HINT_CACHE_STORE_MODE = "jakarta.persistence.cache.storeMode";
String HINT_SPEC_CACHE_STORE_MODE = "jakarta.persistence.cache.storeMode";
}

View File

@ -0,0 +1,80 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.jpa.internal;
import java.util.function.Function;
import org.hibernate.internal.log.DeprecationLogger;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
/**
* @author Steve Ebersole
*/
public class LegacySpecHelper {
private LegacySpecHelper() {
// helper - disallow instantiation
}
public static Object getValue(
String specName,
String javaeeName,
Function<String,?> valueAccess) {
return getValue( specName, javaeeName, valueAccess, null );
}
public static Object getValue(
String specName,
String javaeeName,
Function<String,?> valueAccess,
Function<Object,Boolean> valueChecker) {
final Object specValue = valueAccess.apply( specName );
if ( specValue != null ) {
if ( valueChecker == null || valueChecker.apply( specValue ) ) {
return specValue;
}
}
final Object javaeeValue = valueAccess.apply( javaeeName );
if ( javaeeValue != null ) {
DEPRECATION_LOGGER.deprecatedSetting( javaeeName, specName );
if ( valueChecker == null || valueChecker.apply( javaeeValue ) ) {
return javaeeValue;
}
}
return null;
}
public static Integer getInteger(String specName, String javaeeName, Function<String,?> valueAccess) {
final Object rawValue = getValue( specName, javaeeName, valueAccess );
if ( rawValue == null ) {
return null;
}
if ( rawValue instanceof Integer ) {
return ( (Integer) rawValue );
}
return Integer.valueOf( rawValue.toString() );
}
public static Integer getInteger(
String specName,
String javaeeName,
Function<String,?> valueAccess,
Function<Object,Boolean> valueChecker) {
final Object rawValue = getValue( specName, javaeeName, valueAccess, valueChecker );
if ( rawValue == null ) {
return null;
}
if ( rawValue instanceof Integer ) {
return ( (Integer) rawValue );
}
return Integer.valueOf( rawValue.toString() );
}
}

View File

@ -7,8 +7,6 @@
package org.hibernate.query.internal;
import java.util.Map;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
@ -16,10 +14,19 @@ import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.QueryHints;
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE;
import static org.hibernate.jpa.HibernateHints.HINT_CACHE_MODE;
import static org.hibernate.jpa.HibernateHints.HINT_CACHE_REGION;
import static org.hibernate.jpa.HibernateHints.HINT_FLUSH_MODE;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
/**
* @author Steve Ebersole
*/
@ -54,7 +61,7 @@ public class NamedQueryHelper {
cacheMode = cacheable ? determineCacheMode( hints, sessionFactory ) : null;
flushMode = determineFlushMode( hints, sessionFactory );
readOnly = ConfigurationHelper.getBoolean( QueryHints.HINT_READONLY, hints, false );
readOnly = ConfigurationHelper.getBoolean( HINT_READ_ONLY, hints, false );
lockOptions = determineLockOptions( hints, sessionFactory );
@ -145,17 +152,17 @@ public class NamedQueryHelper {
private static boolean isCacheable(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
return sessionFactory.getSessionFactoryOptions().isQueryCacheEnabled()
&& ConfigurationHelper.getBoolean( QueryHints.HINT_CACHEABLE, hints, false );
&& ConfigurationHelper.getBoolean( HINT_CACHEABLE, hints, false );
}
private static String determineCacheRegion(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
assert sessionFactory.getSessionFactoryOptions().isQueryCacheEnabled();
return ConfigurationHelper.getString( QueryHints.HINT_CACHE_REGION, hints );
return ConfigurationHelper.getString( HINT_CACHE_REGION, hints );
}
private static CacheMode determineCacheMode(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
assert sessionFactory.getSessionFactoryOptions().isQueryCacheEnabled();
final Object setting = hints.get( QueryHints.HINT_CACHE_MODE );
final Object setting = hints.get( HINT_CACHE_MODE );
if ( setting != null ) {
if ( CacheMode.class.isInstance( setting ) ) {
@ -172,15 +179,15 @@ public class NamedQueryHelper {
}
private static FlushMode determineFlushMode(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
final Object setting = hints.get( QueryHints.HINT_FLUSH_MODE );
final Object setting = hints.get( HINT_FLUSH_MODE );
if ( setting != null ) {
if ( FlushMode.class.isInstance( setting ) ) {
if ( setting instanceof FlushMode ) {
return (FlushMode) setting;
}
if ( FlushModeType.class.isInstance( setting ) ) {
return FlushModeTypeHelper.getFlushMode( FlushModeType.class.cast( setting ) );
if ( setting instanceof FlushModeType ) {
return FlushModeTypeHelper.getFlushMode( (FlushModeType) setting );
}
final FlushMode mode = FlushMode.interpretExternalSetting( setting.toString() );
@ -193,16 +200,16 @@ public class NamedQueryHelper {
}
private static LockOptions determineLockOptions(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
final Object lockModeSetting = hints.get( QueryHints.HINT_NATIVE_LOCKMODE );
final Object lockModeSetting = hints.get( HINT_NATIVE_LOCK_MODE );
final LockMode lockMode;
if ( lockModeSetting == null ) {
lockMode = LockMode.NONE;
}
else if ( LockMode.class.isInstance( lockModeSetting ) ) {
lockMode = LockMode.class.cast( lockModeSetting );
else if ( lockModeSetting instanceof LockMode ) {
lockMode = (LockMode) lockModeSetting;
}
else if ( LockModeType.class.isInstance( lockModeSetting ) ) {
lockMode = LockModeTypeHelper.getLockMode( LockModeType.class.cast( lockModeSetting ) );
else if ( lockModeSetting instanceof LockModeType ) {
lockMode = LockModeTypeHelper.getLockMode( (LockModeType) lockModeSetting );
}
else {
lockMode = LockMode.fromExternalForm( lockModeSetting.toString() );

View File

@ -1,4 +1,3 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@ -13,4 +12,4 @@
*
* @author Steve Ebersole
*/
package org.hibernate.query.named;
package org.hibernate.query.named;

View File

@ -35,10 +35,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.internal.EntityManagerMessageLogger;
import org.hibernate.internal.HEMLogging;
import org.hibernate.jpa.HibernateHints;
import org.hibernate.jpa.LegacySpecHints;
import org.hibernate.jpa.QueryHints;
import org.hibernate.jpa.SpecHints;
import org.hibernate.jpa.AvailableHints;
import org.hibernate.jpa.internal.util.ConfigurationHelper;
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
@ -82,6 +79,7 @@ import static org.hibernate.jpa.HibernateHints.HINT_FOLLOW_ON_LOCKING;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_SPACES;
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
import static org.hibernate.jpa.HibernateHints.HINT_TIMEOUT;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_RETRIEVE_MODE;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_STORE_MODE;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH;
@ -89,14 +87,13 @@ import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOAD_GRAPH;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOCK_SCOPE;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOCK_TIMEOUT;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT;
import static org.hibernate.jpa.QueryHints.HINT_NATIVE_LOCKMODE;
import static org.hibernate.jpa.SpecHints.HINT_CACHE_RETRIEVE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_CACHE_STORE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_LOAD_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_LOCK_SCOPE;
import static org.hibernate.jpa.SpecHints.HINT_LOCK_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_QUERY_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_STORE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_SCOPE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
/**
* @author Steve Ebersole
@ -370,7 +367,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
@SuppressWarnings( {"UnusedDeclaration"})
public Set<String> getSupportedHints() {
return QueryHints.getDefinedHints();
return AvailableHints.getDefinedHints();
}
@Override
@ -387,18 +384,18 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
@SuppressWarnings("deprecation")
protected void collectHints(Map<String, Object> hints) {
if ( getQueryOptions().getTimeout() != null ) {
hints.put( HibernateHints.HINT_TIMEOUT, getQueryOptions().getTimeout() );
hints.put( HINT_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
hints.put( HINT_TIMEOUT, getQueryOptions().getTimeout() );
hints.put( HINT_SPEC_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
hints.put( HINT_JAVAEE_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
}
if ( getLockOptions().getTimeOut() != WAIT_FOREVER ) {
hints.put( HINT_LOCK_TIMEOUT, getLockOptions().getTimeOut() );
hints.put( HINT_SPEC_LOCK_TIMEOUT, getLockOptions().getTimeOut() );
hints.put( HINT_JAVAEE_LOCK_TIMEOUT, getLockOptions().getTimeOut() );
}
if ( getLockOptions().getScope() ) {
hints.put( HINT_LOCK_SCOPE, getLockOptions().getScope() );
hints.put( HINT_SPEC_LOCK_SCOPE, getLockOptions().getScope() );
hints.put( HINT_JAVAEE_LOCK_SCOPE, getLockOptions().getScope() );
}
@ -417,8 +414,8 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
if ( getCacheMode() != null ) {
putIfNotNull( hints, HINT_CACHE_MODE, getCacheMode() );
putIfNotNull( hints, HINT_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
putIfNotNull( hints, HINT_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
putIfNotNull( hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
putIfNotNull( hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
putIfNotNull( hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
putIfNotNull( hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
}
@ -454,22 +451,22 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
boolean applied = false;
try {
if ( QueryHints.HINT_TIMEOUT.equals( hintName ) ) {
if ( HINT_TIMEOUT.equals( hintName ) ) {
applied = applyTimeoutHint( ConfigurationHelper.getInteger( value ) );
}
else if ( HINT_QUERY_TIMEOUT.equals( hintName )
else if ( HINT_SPEC_QUERY_TIMEOUT.equals( hintName )
|| HINT_JAVAEE_QUERY_TIMEOUT.equals( hintName ) ) {
if ( HINT_JAVAEE_QUERY_TIMEOUT.equals( hintName ) ) {
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_QUERY_TIMEOUT, HINT_QUERY_TIMEOUT );
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_QUERY_TIMEOUT, HINT_SPEC_QUERY_TIMEOUT );
}
// convert milliseconds to seconds
int timeout = (int)Math.round( ConfigurationHelper.getInteger( value ).doubleValue() / 1000.0 );
applied = applyTimeoutHint( timeout );
}
else if ( HINT_LOCK_TIMEOUT.equals( hintName )
else if ( HINT_SPEC_LOCK_TIMEOUT.equals( hintName )
|| HINT_JAVAEE_LOCK_TIMEOUT.equals( hintName ) ) {
if ( HINT_JAVAEE_LOCK_TIMEOUT.equals( hintName ) ) {
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_LOCK_TIMEOUT, HINT_LOCK_TIMEOUT );
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_LOCK_TIMEOUT, HINT_SPEC_LOCK_TIMEOUT );
}
applied = applyLockTimeoutHint( ConfigurationHelper.getInteger( value ) );
}
@ -494,23 +491,23 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
else if ( HINT_CACHE_MODE.equals( hintName ) ) {
applied = applyCacheModeHint( ConfigurationHelper.getCacheMode( value ) );
}
else if ( HINT_CACHE_RETRIEVE_MODE.equals( hintName )
else if ( HINT_SPEC_CACHE_RETRIEVE_MODE.equals( hintName )
|| HINT_JAVAEE_CACHE_RETRIEVE_MODE.equals( hintName ) ) {
if ( HINT_JAVAEE_CACHE_RETRIEVE_MODE.equals( hintName ) ) {
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_CACHE_RETRIEVE_MODE, HINT_CACHE_RETRIEVE_MODE );
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_CACHE_RETRIEVE_MODE, HINT_SPEC_CACHE_RETRIEVE_MODE );
}
final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf( value.toString() ) : null;
applied = applyJpaCacheRetrieveMode( retrieveMode );
}
else if ( HINT_CACHE_STORE_MODE.equals( hintName )
else if ( HINT_SPEC_CACHE_STORE_MODE.equals( hintName )
|| HINT_JAVAEE_CACHE_STORE_MODE.equals( hintName ) ) {
if ( HINT_JAVAEE_CACHE_STORE_MODE.equals( hintName ) ) {
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_CACHE_STORE_MODE, HINT_CACHE_STORE_MODE );
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_CACHE_STORE_MODE, HINT_SPEC_CACHE_STORE_MODE );
}
final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf( value.toString() ) : null;
applied = applyJpaCacheStoreMode( storeMode );
}
else if ( HINT_NATIVE_LOCKMODE.equals( hintName ) ) {
else if ( HINT_NATIVE_LOCK_MODE.equals( hintName ) ) {
applied = applyNativeQueryLockMode( value );
}
else if ( hintName.startsWith( HINT_NATIVE_LOCK_MODE ) ) {
@ -527,7 +524,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
applied = false;
}
}
else if ( HINT_FETCH_GRAPH.equals( hintName ) || HINT_LOAD_GRAPH.equals( hintName ) ) {
else if ( HINT_SPEC_FETCH_GRAPH.equals( hintName ) || HINT_SPEC_LOAD_GRAPH.equals( hintName ) ) {
if ( value instanceof RootGraphImplementor ) {
applyEntityGraphQueryHint( hintName, (RootGraphImplementor<?>) value );
}
@ -540,10 +537,10 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
}
else if ( HINT_JAVAEE_FETCH_GRAPH.equals( hintName ) || HINT_JAVAEE_LOAD_GRAPH.equals( hintName ) ) {
if ( HINT_JAVAEE_FETCH_GRAPH.equals( hintName ) ) {
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_FETCH_GRAPH, HINT_FETCH_GRAPH );
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_FETCH_GRAPH, HINT_SPEC_FETCH_GRAPH );
}
else {
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_LOAD_GRAPH, HINT_LOAD_GRAPH );
DEPRECATION_LOGGER.deprecatedSetting( HINT_JAVAEE_LOAD_GRAPH, HINT_SPEC_LOAD_GRAPH );
}
if ( value instanceof RootGraphImplementor ) {

View File

@ -99,7 +99,7 @@ import jakarta.persistence.TemporalType;
import jakarta.persistence.Tuple;
import jakarta.persistence.metamodel.SingularAttribute;
import static org.hibernate.jpa.QueryHints.HINT_NATIVE_LOCKMODE;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
/**
* @author Steve Ebersole
@ -1128,7 +1128,7 @@ public class NativeQueryImpl<R>
protected void collectHints(Map<String, Object> hints) {
super.collectHints( hints );
putIfNotNull( hints, HINT_NATIVE_LOCKMODE, getLockOptions().getLockMode() );
putIfNotNull( hints, HINT_NATIVE_LOCK_MODE, getLockOptions().getLockMode() );
}
@Override
@ -1181,7 +1181,7 @@ public class NativeQueryImpl<R>
throw new IllegalArgumentException(
String.format(
"Native lock-mode hint [%s] must specify %s or %s. Encountered type : %s",
HINT_NATIVE_LOCKMODE,
HINT_NATIVE_LOCK_MODE,
LockMode.class.getName(),
LockModeType.class.getName(),
value.getClass().getName()

View File

@ -8,15 +8,6 @@ package org.hibernate.orm.test.bytecode.enhancement.lazyCache;
import java.util.Date;
import java.util.Locale;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@ -27,7 +18,6 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.graph.RootGraph;
import org.hibernate.jpa.QueryHints;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
@ -36,7 +26,18 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import static org.hibernate.Hibernate.isPropertyInitialized;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
@ -86,7 +87,7 @@ public class InitFromCacheTest extends BaseCoreFunctionalTestCase {
final RootGraph<Document> entityGraph = s.createEntityGraph( Document.class );
entityGraph.addAttributeNodes( "text", "summary" );
final Document document = s.createQuery( "from Document", Document.class )
.setHint( QueryHints.JAKARTA_HINT_FETCH_GRAPH, entityGraph )
.setHint( HINT_SPEC_FETCH_GRAPH, entityGraph )
.uniqueResult();
assertTrue( isPropertyInitialized( document, "text" ) );
assertTrue( isPropertyInitialized( document, "summary" ) );

View File

@ -6,29 +6,28 @@
*/
package org.hibernate.orm.test.immutable.entitywithmutablecollection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import org.hibernate.QueryException;
import org.hibernate.StaleObjectStateException;
import org.hibernate.StaleStateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jpa.QueryHints;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH;
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@ -1199,7 +1198,7 @@ public abstract class AbstractEntityWithOneToManyTest {
CriteriaQuery<Contract> criteria = criteriaBuilder.createQuery( Contract.class );
criteria.from( Contract.class );
return s.createQuery( criteria )
.setHint( QueryHints.HINT_FETCHGRAPH, s.createEntityGraph( Contract.class ) )
.setHint( HINT_JAVAEE_FETCH_GRAPH, s.createEntityGraph( Contract.class ) )
.uniqueResult();
}
@ -1208,7 +1207,7 @@ public abstract class AbstractEntityWithOneToManyTest {
CriteriaQuery<ContractVariation> criteria = criteriaBuilder.createQuery( ContractVariation.class );
criteria.from( ContractVariation.class );
return s.createQuery( criteria )
.setHint( QueryHints.HINT_FETCHGRAPH, s.createEntityGraph( ContractVariation.class ) )
.setHint( HINT_JAVAEE_FETCH_GRAPH, s.createEntityGraph( ContractVariation.class ) )
.uniqueResult();
}
@ -1217,7 +1216,7 @@ public abstract class AbstractEntityWithOneToManyTest {
CriteriaQuery<Party> criteria = criteriaBuilder.createQuery( Party.class );
criteria.from( Party.class );
return s.createQuery( criteria )
.setHint( QueryHints.HINT_FETCHGRAPH, s.createEntityGraph( Party.class ) )
.setHint( HINT_JAVAEE_FETCH_GRAPH, s.createEntityGraph( Party.class ) )
.uniqueResult();
}

View File

@ -21,7 +21,6 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.jpa.QueryHints;
import org.hibernate.stat.Statistics;
import org.hibernate.testing.TestForIssue;
@ -34,6 +33,7 @@ import jakarta.persistence.FlushModeType;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.Query;
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -507,7 +507,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
em = getOrCreateEntityManager();
Map<String, Object> hints = new HashMap<>();
hints.put(QueryHints.HINT_READONLY, true);
hints.put(HINT_READ_ONLY, true);
em.getTransaction().begin();

View File

@ -32,7 +32,7 @@ import static org.hibernate.jpa.HibernateHints.HINT_COMMENT;
import static org.hibernate.jpa.HibernateHints.HINT_FETCH_SIZE;
import static org.hibernate.jpa.HibernateHints.HINT_FLUSH_MODE;
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
import static org.hibernate.jpa.SpecHints.HINT_QUERY_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
/**
* @author Gavin King
@ -62,7 +62,7 @@ import static org.hibernate.jpa.SpecHints.HINT_QUERY_TIMEOUT;
query = "select i from Item i",
lockMode = LockModeType.PESSIMISTIC_WRITE,
hints = {
@QueryHint( name = HINT_QUERY_TIMEOUT, value = "3000" ),
@QueryHint( name = HINT_SPEC_QUERY_TIMEOUT, value = "3000" ),
@QueryHint( name = HINT_CACHE_MODE, value = "ignore" ),
@QueryHint( name = HINT_CACHEABLE, value = "true" ),
@QueryHint( name = HINT_READ_ONLY, value = "true" ),

View File

@ -11,14 +11,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import jakarta.persistence.Subgraph;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.jpa.QueryHints;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.orm.test.jpa.graphs.Company;
@ -34,7 +29,14 @@ import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import jakarta.persistence.Subgraph;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -55,7 +57,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
entityGraph.addAttributeNodes( "location" );
entityGraph.addAttributeNodes( "markets" );
Query query = entityManager.createQuery( "from " + Company.class.getName() );
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
Company company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -79,7 +81,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
subSubgraph.addAttributeNodes( "friends" );
query = entityManager.createQuery( "from " + Company.class.getName() );
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -121,7 +123,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
entityGraph.addAttributeNodes( "location" );
entityGraph.addAttributeNodes( "markets" );
Query query = entityManager.createQuery( "from " + Company.class.getName() );
query.setHint( QueryHints.HINT_FETCHGRAPH, entityGraph );
query.setHint( HINT_JAVAEE_FETCH_GRAPH, entityGraph );
Company company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -145,7 +147,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
subSubgraph.addAttributeNodes( "friends" );
query = entityManager.createQuery( "from " + Company.class.getName() );
query.setHint( QueryHints.HINT_FETCHGRAPH, entityGraph );
query.setHint( HINT_JAVAEE_FETCH_GRAPH, entityGraph );
company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -188,7 +190,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
EntityGraph<CompanyFetchProfile> entityGraph = entityManager.createEntityGraph( CompanyFetchProfile.class );
entityGraph.addAttributeNodes( "markets" );
Query query = entityManager.createQuery( "from " + CompanyFetchProfile.class.getName() );
query.setHint( QueryHints.HINT_FETCHGRAPH, entityGraph );
query.setHint( HINT_JAVAEE_FETCH_GRAPH, entityGraph );
CompanyFetchProfile company = (CompanyFetchProfile) query.getSingleResult();
entityManager.getTransaction().commit();
@ -212,7 +214,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
subSubgraph.addAttributeNodes( "friends" );
query = entityManager.createQuery( "from " + CompanyFetchProfile.class.getName() );
query.setHint( QueryHints.HINT_FETCHGRAPH, entityGraph );
query.setHint( HINT_JAVAEE_FETCH_GRAPH, entityGraph );
company = (CompanyFetchProfile) query.getSingleResult();
entityManager.getTransaction().commit();
@ -268,7 +270,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
//entityGraph.addAttributeNodes( "location" );
entityGraph.addAttributeNodes( "markets" );
Query query = entityManager.createQuery( "from " + Company.class.getName() + " c order by c.location.zip, c.id" );
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
List results = query.getResultList();
// - 1st will be the Company with location.zip == 11234 with an empty markets collection
@ -318,7 +320,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
entityGraph.addAttributeNodes( "markets" );
Query query = entityManager.createQuery( "from " + Company.class.getName() + " where location.zip = :zip")
.setParameter( "zip", 12345 );
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
Company company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -343,7 +345,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
query = entityManager.createQuery( "from " + Company.class.getName() + " where location.zip = :zip" )
.setParameter( "zip", 12345 );
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -386,7 +388,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
// Ensure the EntityGraph and explicit fetches do not conflict.
Query query = entityManager.createQuery( "from " + Company.class.getName()
+ " as c left join fetch c.location left join fetch c.employees" );
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
Company company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -414,7 +416,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
Query query = entityManager.createQuery( "from " + Company.class.getName()
+ " as c left join fetch c.location left join fetch c.employees where c.location.zip = :zip")
.setParameter("zip", 12345);
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
Company company = (Company) query.getSingleResult();
entityManager.getTransaction().commit();
@ -437,7 +439,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
EntityGraph<Company> entityGraph = entityManager.createEntityGraph(Company.class);
entityGraph.addAttributeNodes("location");
Query query = entityManager.createQuery("select c from " + Company.class.getName() + " c where c.employees IS EMPTY");
query.setHint(QueryHints.HINT_LOADGRAPH, entityGraph);
query.setHint(HINT_SPEC_LOAD_GRAPH, entityGraph);
query.getResultList();
entityManager.getTransaction().commit();
@ -479,7 +481,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
EntityGraph<?> graph = entityManager.getEntityGraph( "Student.Full" );
List<Student> students = entityManager.createNamedQuery( "LIST_OF_STD", Student.class )
.setHint( QueryHints.HINT_FETCHGRAPH, graph )
.setHint( HINT_JAVAEE_FETCH_GRAPH, graph )
.getResultList();
assertEquals( 2, students.size() );

View File

@ -25,8 +25,8 @@ import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.jpa.QueryHints;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.RequiresDialectFeature;
@ -46,6 +46,7 @@ import jakarta.persistence.PessimisticLockException;
import jakarta.persistence.Query;
import jakarta.persistence.QueryTimeoutException;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -928,7 +929,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
"select L from Lock_ L where L.id < 10000 "
);
query.setLockMode( LockModeType.PESSIMISTIC_READ );
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 500 ); // 1 sec timeout
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 500 ); // 1 sec timeout
List<Lock> resultList = query.getResultList();
String name = resultList.get( 0 ).getName(); // force entity to be read
log.info( "testQueryTimeout: name read =" + name );
@ -995,7 +996,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
final CountDownLatch latch = new CountDownLatch( 1 );
final Map<String, Object> timeoutProps = new HashMap<String, Object>();
timeoutProps.put( QueryHints.SPEC_HINT_TIMEOUT, 500 ); // 1 sec timeout (should round up)
timeoutProps.put( HINT_SPEC_QUERY_TIMEOUT, 500 ); // 1 sec timeout (should round up)
final Lock lock = new Lock();
FutureTask<Boolean> bgTask = new FutureTask<>(

View File

@ -6,18 +6,19 @@
*/
package org.hibernate.orm.test.jpa.lock;
import java.util.Map;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.jpa.QueryHints;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.util.ExceptionUtil;
import org.junit.Test;
import java.util.Map;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -31,7 +32,7 @@ import static org.junit.Assert.fail;
public class NativeSQLQueryTimeoutTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected void addConfigOptions(Map options) {
options.put( QueryHints.SPEC_HINT_TIMEOUT, "500" );
options.put( HINT_SPEC_QUERY_TIMEOUT, "500" );
}
@Test

View File

@ -12,7 +12,6 @@ import org.hibernate.LockMode;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.internal.SessionImpl;
import org.hibernate.jpa.QueryHints;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.NativeQuery;
@ -36,6 +35,7 @@ import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.ParameterExpression;
import jakarta.persistence.criteria.Root;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -67,7 +67,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
assertNull( query.getLockOptions().getAliasSpecificLockMode( "l" ) );
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getEffectiveLockMode( "l" ) );
query.setHint( QueryHints.HINT_NATIVE_LOCKMODE + ".l", LockModeType.PESSIMISTIC_WRITE );
query.setHint( HINT_NATIVE_LOCK_MODE + ".l", LockModeType.PESSIMISTIC_WRITE );
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getLockMode() );
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getAliasSpecificLockMode( "l" ) );
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getEffectiveLockMode( "l" ) );
@ -124,13 +124,13 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
}
// however, we should be able to set it using hints
query.setHint( QueryHints.HINT_NATIVE_LOCKMODE, LockModeType.READ );
query.setHint( HINT_NATIVE_LOCK_MODE, LockModeType.READ );
// NOTE : LockModeType.READ should map to LockMode.OPTIMISTIC
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getLockMode() );
assertNull( query.getLockOptions().getAliasSpecificLockMode( "l" ) );
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getEffectiveLockMode( "l" ) );
query.setHint( QueryHints.HINT_NATIVE_LOCKMODE +".l", LockModeType.PESSIMISTIC_WRITE );
query.setHint( HINT_NATIVE_LOCK_MODE +".l", LockModeType.PESSIMISTIC_WRITE );
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getLockMode() );
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getAliasSpecificLockMode( "l" ) );
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getEffectiveLockMode( "l" ) );
@ -180,7 +180,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
em = getOrCreateEntityManager();
em.getTransaction().begin();
Lockable reread = em.createQuery( "from Lockable l", Lockable.class )
.setHint( QueryHints.HINT_NATIVE_LOCKMODE + ".l", LockModeType.PESSIMISTIC_FORCE_INCREMENT )
.setHint( HINT_NATIVE_LOCK_MODE + ".l", LockModeType.PESSIMISTIC_FORCE_INCREMENT )
.getSingleResult();
assertFalse( reread.getVersion().equals( initial ) );
em.getTransaction().commit();
@ -233,7 +233,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
em = getOrCreateEntityManager();
em.getTransaction().begin();
Lockable reread = em.createQuery( "from Lockable l", Lockable.class )
.setHint( QueryHints.HINT_NATIVE_LOCKMODE + ".l", LockModeType.OPTIMISTIC_FORCE_INCREMENT )
.setHint( HINT_NATIVE_LOCK_MODE + ".l", LockModeType.OPTIMISTIC_FORCE_INCREMENT )
.getSingleResult();
assertEquals( initial, reread.getVersion() );
em.getTransaction().commit();
@ -315,7 +315,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
em = getOrCreateEntityManager();
em.getTransaction().begin();
Lockable reread = em.createQuery( "from Lockable l", Lockable.class )
.setHint( QueryHints.HINT_NATIVE_LOCKMODE + ".l", LockModeType.OPTIMISTIC )
.setHint( HINT_NATIVE_LOCK_MODE + ".l", LockModeType.OPTIMISTIC )
.getSingleResult();
assertEquals( initial, reread.getVersion() );
assertTrue( em.unwrap( SessionImpl.class ).getActionQueue().hasBeforeTransactionActions() );

View File

@ -12,7 +12,6 @@ import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jpa.QueryHints;
import org.hibernate.stat.Statistics;
import org.hibernate.testing.TestForIssue;
@ -26,6 +25,7 @@ import org.junit.jupiter.api.Test;
import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.TypedQuery;
import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -86,7 +86,7 @@ public class CachedQueryTest {
scope.inTransaction(
em -> {
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
.setHint( QueryHints.HINT_CACHEABLE, true );
.setHint( HINT_CACHEABLE, true );
List<Employee> employees = query.getResultList();
assertEquals( 10, employees.size() );
assertEquals( 0, stats.getQueryCacheHitCount() );
@ -109,7 +109,7 @@ public class CachedQueryTest {
scope.inTransaction(
em -> {
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
.setHint( QueryHints.HINT_CACHEABLE, true );
.setHint( HINT_CACHEABLE, true );
List<Employee> employees = query.getResultList();
assertEquals( 10, employees.size() );
assertEquals( 1, stats.getQueryCacheHitCount() );
@ -133,7 +133,7 @@ public class CachedQueryTest {
scope.inTransaction(
em -> {
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
.setHint( QueryHints.HINT_CACHEABLE, true );
.setHint( HINT_CACHEABLE, true );
List<Employee> employees = query.getResultList();
assertEquals( 10, employees.size() );
// query is still found in the cache
@ -164,7 +164,7 @@ public class CachedQueryTest {
em.getTransaction().begin();
try {
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
.setHint( QueryHints.HINT_CACHEABLE, true );
.setHint( HINT_CACHEABLE, true );
List<Employee> employees = query.getResultList();
assertEquals( 10, employees.size() );
// query is no longer found in the cache

View File

@ -7,6 +7,17 @@
package org.hibernate.orm.test.jpa.query;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.NativeQuery;
import org.hibernate.testing.TestForIssue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
@ -16,17 +27,7 @@ import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Query;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.jpa.QueryHints;
import org.hibernate.query.NativeQuery;
import org.hibernate.testing.TestForIssue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
@ -199,9 +200,9 @@ public class NamedQueryTest extends BaseEntityManagerFunctionalTestCase {
public void testQueryHintLockMode() {
doInJPA( this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery( "NamedNativeQuery" );
query.setHint( QueryHints.HINT_NATIVE_LOCKMODE, "none" );
query.setHint( HINT_NATIVE_LOCK_MODE, "none" );
query.setParameter( 1, GAME_TITLES[0] );
assertEquals( LockMode.NONE, query.getHints().get( QueryHints.HINT_NATIVE_LOCKMODE ) );
assertEquals( LockMode.NONE, query.getHints().get( HINT_NATIVE_LOCK_MODE ) );
}
);
}

View File

@ -1,10 +1,6 @@
package org.hibernate.orm.test.loading;
import java.util.Collections;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.jpa.QueryHints;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
@ -14,8 +10,12 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
@DomainModel(
annotatedClasses = {
@ -42,7 +42,7 @@ public class ReadonlyHintTest {
@Test
void testWithReadOnlyHint(SessionFactoryScope scope) {
scope.inTransaction( session -> {
SimpleEntity fetchedEntity = session.find( SimpleEntity.class, 1L, Collections.singletonMap( QueryHints.HINT_READONLY, true ) );
SimpleEntity fetchedEntity = session.find( SimpleEntity.class, 1L, Collections.singletonMap( HINT_READ_ONLY, true ) );
fetchedEntity.name = CHANGED_NAME;
} );

View File

@ -6,15 +6,10 @@
*/
package org.hibernate.orm.test.query;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import jakarta.persistence.Query;
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.LockMode;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.jpa.QueryHints;
import org.hibernate.orm.test.jpa.Distributor;
import org.hibernate.orm.test.jpa.Item;
import org.hibernate.orm.test.jpa.Wallet;
@ -24,6 +19,12 @@ import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import jakarta.persistence.Query;
import static org.hibernate.jpa.HibernateHints.HINT_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@ -173,7 +174,7 @@ public class AddNamedQueryTest {
// jpa timeout is in milliseconds, whereas Hibernate's is in seconds
assertEquals( (Integer) 3, hibernateQuery.getTimeout() );
query.setHint( QueryHints.HINT_TIMEOUT, 10 );
query.setHint( HINT_TIMEOUT, 10 );
em.getEntityManagerFactory().addNamedQuery( name, query );
query = em.createNamedQuery( name );
@ -189,7 +190,7 @@ public class AddNamedQueryTest {
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 10000 );
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 10000 );
em.getEntityManagerFactory().addNamedQuery( name, query );
query = em.createNamedQuery( name );

View File

@ -10,8 +10,6 @@ import java.time.LocalDate;
import java.util.Collections;
import org.hibernate.graph.GraphParser;
import org.hibernate.jpa.QueryHints;
import org.hibernate.query.IllegalQueryOperationException;
import org.hibernate.testing.orm.assertj.HibernateInitializedCondition;
import org.hibernate.testing.orm.domain.StandardDomainModel;
@ -25,8 +23,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.fail;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
/**
* @author Steve Ebersole
@ -38,7 +36,7 @@ public class QueryHintTest {
public void testFetchGraphHint(SessionFactoryScope scope) {
final Contact queried = scope.fromTransaction( (session) -> {
return session.createQuery( "from Contact", Contact.class )
.setHint( QueryHints.HINT_FETCHGRAPH, GraphParser.parse( Contact.class, "phoneNumbers", session ) )
.setHint( HINT_SPEC_FETCH_GRAPH, GraphParser.parse( Contact.class, "phoneNumbers", session ) )
.uniqueResult();
} );
@ -50,7 +48,7 @@ public class QueryHintTest {
public void testLoadGraphHint(SessionFactoryScope scope) {
final Contact queried = scope.fromTransaction( (session) -> {
return session.createQuery( "from Contact", Contact.class )
.setHint( QueryHints.HINT_LOADGRAPH, GraphParser.parse( Contact.class, "phoneNumbers", session ) )
.setHint( HINT_SPEC_LOAD_GRAPH, GraphParser.parse( Contact.class, "phoneNumbers", session ) )
.uniqueResult();
} );

View File

@ -9,14 +9,10 @@ package org.hibernate.orm.test.query;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.jpa.QueryHints;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.hibernate.type.descriptor.java.StringJavaType;
@ -30,6 +26,11 @@ import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.Before;
import org.junit.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.times;
@ -111,7 +112,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
doInHibernate(
this::sessionFactory, session -> {
Query query = session.createQuery( QUERY );
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 );
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 123000 );
query.executeUpdate();
try {
@ -161,7 +162,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
doInHibernate(
this::sessionFactory, session -> {
NativeQuery query = session.createNativeQuery( QUERY );
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 );
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 123000 );
query.executeUpdate();
try {
@ -199,7 +200,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
doInHibernate(
this::sessionFactory, session -> {
NativeQuery query = session.createNativeQuery( QUERY );
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 );
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 123000 );
query.executeUpdate();
try {

View File

@ -10,6 +10,17 @@ import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NamedNativeQuery;
import org.hibernate.cache.spi.CacheImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityResult;
@ -19,19 +30,9 @@ import jakarta.persistence.QueryHint;
import jakarta.persistence.SqlResultSetMapping;
import jakarta.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NamedNativeQuery;
import org.hibernate.cache.spi.CacheImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jpa.QueryHints;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_SPACES;
/**
* @author Steve Ebersole
@ -178,7 +179,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
checkUseCase(
tableName,
query -> query.setHint( QueryHints.HINT_NATIVE_SPACES, tableName ),
query -> query.setHint( HINT_NATIVE_SPACES, tableName ),
// the 2 CachedEntity entries should still be there
true
);
@ -203,7 +204,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
checkUseCase(
tableName,
query -> query.setHint( QueryHints.HINT_NATIVE_SPACES, spaces ),
query -> query.setHint( HINT_NATIVE_SPACES, spaces ),
// the 2 CachedEntity entries should still be there
true
);
@ -227,7 +228,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
checkUseCase(
tableName,
query -> query.setHint( QueryHints.HINT_NATIVE_SPACES, spaces ),
query -> query.setHint( HINT_NATIVE_SPACES, spaces ),
// the 2 CachedEntity entries should still be there
true
);
@ -382,7 +383,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
name = "NonCachedEntity_hint_jpa",
query = "select * from non_cached_entity",
hints = {
@QueryHint( name = QueryHints.HINT_NATIVE_SPACES, value = "non_cached_entity" )
@QueryHint( name = HINT_NATIVE_SPACES, value = "non_cached_entity" )
}
)
public static class NonCachedEntity {