api, spi, internal, deprecation
org.hibernate.query package
This commit is contained in:
parent
2b5a5fc196
commit
8cda382ef9
|
@ -9,6 +9,19 @@ package org.hibernate.userguide.caching;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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.CacheRetrieveMode;
|
||||||
import jakarta.persistence.CacheStoreMode;
|
import jakarta.persistence.CacheStoreMode;
|
||||||
import jakarta.persistence.Cacheable;
|
import jakarta.persistence.Cacheable;
|
||||||
|
@ -18,19 +31,8 @@ import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
import org.hibernate.CacheMode;
|
import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE;
|
||||||
import org.hibernate.Session;
|
import static org.hibernate.jpa.HibernateHints.HINT_CACHE_REGION;
|
||||||
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.testing.transaction.TransactionUtil.doInJPA;
|
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@ -131,8 +133,8 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
"from Person p " +
|
"from Person p " +
|
||||||
"where p.id > :id", Person.class)
|
"where p.id > :id", Person.class)
|
||||||
.setParameter("id", 0L)
|
.setParameter("id", 0L)
|
||||||
.setHint(QueryHints.HINT_CACHEABLE, "true")
|
.setHint(HINT_CACHEABLE, "true")
|
||||||
.setHint(QueryHints.HINT_CACHE_REGION, "query.cache.person")
|
.setHint(HINT_CACHE_REGION, "query.cache.person")
|
||||||
.getResultList();
|
.getResultList();
|
||||||
//end::caching-query-region-jpa-example[]
|
//end::caching-query-region-jpa-example[]
|
||||||
});
|
});
|
||||||
|
@ -159,8 +161,8 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
"from Person p " +
|
"from Person p " +
|
||||||
"where p.id > :id", Person.class)
|
"where p.id > :id", Person.class)
|
||||||
.setParameter("id", 0L)
|
.setParameter("id", 0L)
|
||||||
.setHint(QueryHints.HINT_CACHEABLE, "true")
|
.setHint(HINT_CACHEABLE, "true")
|
||||||
.setHint(QueryHints.HINT_CACHE_REGION, "query.cache.person")
|
.setHint(HINT_CACHE_REGION, "query.cache.person")
|
||||||
.setHint("jakarta.persistence.cache.storeMode", CacheStoreMode.REFRESH)
|
.setHint("jakarta.persistence.cache.storeMode", CacheStoreMode.REFRESH)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
//end::caching-query-region-store-mode-jpa-example[]
|
//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[]
|
//tag::caching-management-cache-mode-query-jpa-example[]
|
||||||
List<Person> persons = entityManager.createQuery(
|
List<Person> persons = entityManager.createQuery(
|
||||||
"select p from Person p", Person.class)
|
"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.retrieveMode" , CacheRetrieveMode.USE)
|
||||||
.setHint("jakarta.persistence.cache.storeMode" , CacheStoreMode.REFRESH)
|
.setHint("jakarta.persistence.cache.storeMode" , CacheStoreMode.REFRESH)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
|
|
@ -68,9 +68,9 @@ public class QueryHints implements HibernateHints, SpecHints {
|
||||||
public static final String TIMEOUT_HIBERNATE = HibernateHints.HINT_TIMEOUT;
|
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
|
* @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;
|
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;
|
public static final String TIMEOUT_JPA = LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,14 +100,14 @@ public interface AvailableSettings {
|
||||||
String JAKARTA_SHARED_CACHE_MODE = "jakarta.persistence.sharedCache.mode";
|
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
|
* Used to indicate what form of automatic validation is in effect as per rules defined
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class QueryHintDefinition {
|
||||||
// Specialized access
|
// Specialized access
|
||||||
|
|
||||||
public Integer getTimeout() {
|
public Integer getTimeout() {
|
||||||
final Integer jakartaTimeout = getInteger( SpecHints.HINT_QUERY_TIMEOUT );
|
final Integer jakartaTimeout = getInteger( SpecHints.HINT_SPEC_QUERY_TIMEOUT );
|
||||||
if ( jakartaTimeout != null ) {
|
if ( jakartaTimeout != null ) {
|
||||||
// convert milliseconds to seconds
|
// convert milliseconds to seconds
|
||||||
return (int) Math.round( jakartaTimeout.doubleValue() / 1000.0 );
|
return (int) Math.round( jakartaTimeout.doubleValue() / 1000.0 );
|
||||||
|
|
|
@ -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_FETCH_GRAPH;
|
||||||
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOAD_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_SPEC_FETCH_GRAPH;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_LOAD_GRAPH;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPA specifies two distinct ways to apply an {@link jakarta.persistence.EntityGraph} -
|
* JPA specifies two distinct ways to apply an {@link jakarta.persistence.EntityGraph} -
|
||||||
|
@ -27,7 +27,7 @@ public enum GraphSemantic {
|
||||||
* are not fetched.
|
* are not fetched.
|
||||||
* </ul>
|
* </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".
|
* 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}.
|
* depending on the mapping of the attribute, instead of forcing {@code FetchType.LAZY}.
|
||||||
* </ul>
|
* </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 jakartaHintName;
|
||||||
private final String jpaHintName;
|
private final String jpaHintName;
|
||||||
|
|
|
@ -62,7 +62,6 @@ import org.hibernate.event.spi.ReplicateEventListener;
|
||||||
import org.hibernate.event.spi.ResolveNaturalIdEventListener;
|
import org.hibernate.event.spi.ResolveNaturalIdEventListener;
|
||||||
import org.hibernate.event.spi.SaveOrUpdateEventListener;
|
import org.hibernate.event.spi.SaveOrUpdateEventListener;
|
||||||
import org.hibernate.jpa.LegacySpecHints;
|
import org.hibernate.jpa.LegacySpecHints;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.jpa.SpecHints;
|
import org.hibernate.jpa.SpecHints;
|
||||||
import org.hibernate.jpa.internal.util.CacheModeHelper;
|
import org.hibernate.jpa.internal.util.CacheModeHelper;
|
||||||
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
||||||
|
@ -289,11 +288,11 @@ public final class FastSessionServices {
|
||||||
|
|
||||||
//Defaults defined by SessionFactory configuration:
|
//Defaults defined by SessionFactory configuration:
|
||||||
final String[] ENTITY_MANAGER_SPECIFIC_PROPERTIES = {
|
final String[] ENTITY_MANAGER_SPECIFIC_PROPERTIES = {
|
||||||
SpecHints.HINT_LOCK_SCOPE,
|
SpecHints.HINT_SPEC_LOCK_SCOPE,
|
||||||
SpecHints.HINT_LOCK_TIMEOUT,
|
SpecHints.HINT_SPEC_LOCK_TIMEOUT,
|
||||||
SpecHints.HINT_QUERY_TIMEOUT,
|
SpecHints.HINT_SPEC_QUERY_TIMEOUT,
|
||||||
SpecHints.HINT_CACHE_RETRIEVE_MODE,
|
SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE,
|
||||||
SpecHints.HINT_CACHE_STORE_MODE,
|
SpecHints.HINT_SPEC_CACHE_STORE_MODE,
|
||||||
|
|
||||||
AvailableSettings.FLUSH_MODE,
|
AvailableSettings.FLUSH_MODE,
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ import org.hibernate.graph.GraphSemantic;
|
||||||
import org.hibernate.graph.internal.RootGraphImpl;
|
import org.hibernate.graph.internal.RootGraphImpl;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
import org.hibernate.internal.util.ExceptionHelper;
|
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.CacheModeHelper;
|
||||||
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
||||||
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
|
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_LOCK_TIMEOUT;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
|
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.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.
|
* Concrete implementation of a the {@link Session} API.
|
||||||
|
@ -285,33 +290,26 @@ public class SessionImpl
|
||||||
if ( lockOptionsForRead.getLockMode() != LockMode.NONE ) {
|
if ( lockOptionsForRead.getLockMode() != LockMode.NONE ) {
|
||||||
query.setLockMode( getLockMode( lockOptionsForRead.getLockMode() ) );
|
query.setLockMode( getLockMode( lockOptionsForRead.getLockMode() ) );
|
||||||
}
|
}
|
||||||
final Object queryTimeout;
|
|
||||||
if ( ( queryTimeout = getSessionProperty( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
|
final Object specQueryTimeout = LegacySpecHelper.getInteger(
|
||||||
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
|
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 ) {
|
final Integer specLockTimeout = LegacySpecHelper.getInteger(
|
||||||
query.setHint( QueryHints.JAKARTA_SPEC_HINT_TIMEOUT, jakartaQueryTimeout );
|
HINT_SPEC_LOCK_TIMEOUT,
|
||||||
}
|
HINT_JAVAEE_LOCK_TIMEOUT,
|
||||||
final Object lockTimeout;
|
this::getSessionProperty,
|
||||||
final Object jpaLockTimeout = getSessionProperty( JPA_LOCK_TIMEOUT );
|
(value) -> Integer.valueOf( LockOptions.WAIT_FOREVER ).equals( value )
|
||||||
if ( jpaLockTimeout == null ) {
|
);
|
||||||
lockTimeout = getSessionProperty( JAKARTA_LOCK_TIMEOUT );
|
if ( specLockTimeout != null ) {
|
||||||
}
|
query.setHint( HINT_SPEC_LOCK_TIMEOUT, specLockTimeout );
|
||||||
else if ( Integer.valueOf( LockOptions.WAIT_FOREVER ).equals( jpaLockTimeout ) ) {
|
query.setHint( HINT_JAVAEE_LOCK_TIMEOUT, specLockTimeout );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2269,7 +2267,7 @@ public class SessionImpl
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getLoadQueryInfluencers().getEffectiveEntityGraph().applyConfiguredGraph( properties );
|
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 );
|
getLoadQueryInfluencers().setReadOnly( readOnly );
|
||||||
final IdentifierLoadAccess<T> loadAccess = byId( entityClass );
|
final IdentifierLoadAccess<T> loadAccess = byId( entityClass );
|
||||||
loadAccess.with( determineAppropriateLocalCacheMode( properties ) );
|
loadAccess.with( determineAppropriateLocalCacheMode( properties ) );
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa;
|
package org.hibernate.jpa;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import jakarta.persistence.LockModeType;
|
import jakarta.persistence.LockModeType;
|
||||||
|
|
||||||
|
@ -21,5 +23,37 @@ import jakarta.persistence.LockModeType;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,37 +23,37 @@ package org.hibernate.jpa;
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public interface LegacySpecHints {
|
public interface LegacySpecHints {
|
||||||
/**
|
/**
|
||||||
* @see SpecHints#HINT_FETCH_GRAPH
|
* @see SpecHints#HINT_SPEC_FETCH_GRAPH
|
||||||
*/
|
*/
|
||||||
String HINT_JAVAEE_FETCH_GRAPH = "javax.persistence.fetchgraph";
|
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";
|
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";
|
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";
|
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";
|
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";
|
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";
|
String HINT_JAVAEE_CACHE_STORE_MODE = "javax.persistence.cache.storeMode";
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class QueryHints {
|
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
|
* @see HibernateHints#HINT_COMMENT
|
||||||
|
@ -62,24 +62,24 @@ public class QueryHints {
|
||||||
public static final String HINT_NATIVE_LOCKMODE = HibernateHints.HINT_NATIVE_LOCK_MODE;
|
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
|
* @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.
|
* 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;
|
public static final String HINT_TIMEOUT = HibernateHints.HINT_TIMEOUT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see LegacySpecHints#HINT_JAVAEE_QUERY_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;
|
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_SPACES );
|
||||||
hints.add( HibernateHints.HINT_NATIVE_LOCK_MODE );
|
hints.add( HibernateHints.HINT_NATIVE_LOCK_MODE );
|
||||||
|
|
||||||
hints.add( SpecHints.HINT_QUERY_TIMEOUT );
|
hints.add( SpecHints.HINT_SPEC_QUERY_TIMEOUT );
|
||||||
hints.add( SpecHints.HINT_FETCH_GRAPH );
|
hints.add( SpecHints.HINT_SPEC_FETCH_GRAPH );
|
||||||
hints.add( SpecHints.HINT_LOAD_GRAPH );
|
hints.add( SpecHints.HINT_SPEC_LOAD_GRAPH );
|
||||||
|
|
||||||
hints.add( LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT );
|
hints.add( LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT );
|
||||||
hints.add( LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH );
|
hints.add( LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH );
|
||||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.jpa;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.graph.GraphSemantic;
|
import org.hibernate.graph.GraphSemantic;
|
||||||
|
|
||||||
import jakarta.persistence.LockModeType;
|
import jakarta.persistence.LockModeType;
|
||||||
|
@ -31,7 +30,7 @@ public interface SpecHints {
|
||||||
*
|
*
|
||||||
* @see GraphSemantic#FETCH
|
* @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
|
* Hint providing a {@link jakarta.persistence.EntityGraph} which should be
|
||||||
|
@ -39,19 +38,19 @@ public interface SpecHints {
|
||||||
*
|
*
|
||||||
* @see GraphSemantic#LOAD
|
* @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).
|
* 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
|
* Hint indicating whether to extend pessimistic locking to
|
||||||
* associated tables. Expected to be an instance of
|
* associated tables. Expected to be an instance of
|
||||||
* {@link jakarta.persistence.PessimisticLockScope}
|
* {@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
|
* 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
|
* @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
|
* Hint specifying how Hibernate should handle retrieving data from
|
||||||
|
@ -70,7 +69,7 @@ public interface SpecHints {
|
||||||
* @see jakarta.persistence.Query#setHint
|
* @see jakarta.persistence.Query#setHint
|
||||||
* @see org.hibernate.CacheMode
|
* @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
|
* Hint specifying how Hibernate should handle retrieving data from
|
||||||
|
@ -81,6 +80,6 @@ public interface SpecHints {
|
||||||
* @see jakarta.persistence.Query#setHint
|
* @see jakarta.persistence.Query#setHint
|
||||||
* @see org.hibernate.CacheMode
|
* @see org.hibernate.CacheMode
|
||||||
*/
|
*/
|
||||||
String HINT_CACHE_STORE_MODE = "jakarta.persistence.cache.storeMode";
|
String HINT_SPEC_CACHE_STORE_MODE = "jakarta.persistence.cache.storeMode";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -7,8 +7,6 @@
|
||||||
package org.hibernate.query.internal;
|
package org.hibernate.query.internal;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import jakarta.persistence.FlushModeType;
|
|
||||||
import jakarta.persistence.LockModeType;
|
|
||||||
|
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
|
@ -16,10 +14,19 @@ import org.hibernate.LockMode;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
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.FlushModeTypeHelper;
|
||||||
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
|
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
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -54,7 +61,7 @@ public class NamedQueryHelper {
|
||||||
cacheMode = cacheable ? determineCacheMode( hints, sessionFactory ) : null;
|
cacheMode = cacheable ? determineCacheMode( hints, sessionFactory ) : null;
|
||||||
|
|
||||||
flushMode = determineFlushMode( hints, sessionFactory );
|
flushMode = determineFlushMode( hints, sessionFactory );
|
||||||
readOnly = ConfigurationHelper.getBoolean( QueryHints.HINT_READONLY, hints, false );
|
readOnly = ConfigurationHelper.getBoolean( HINT_READ_ONLY, hints, false );
|
||||||
|
|
||||||
lockOptions = determineLockOptions( hints, sessionFactory );
|
lockOptions = determineLockOptions( hints, sessionFactory );
|
||||||
|
|
||||||
|
@ -145,17 +152,17 @@ public class NamedQueryHelper {
|
||||||
|
|
||||||
private static boolean isCacheable(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
private static boolean isCacheable(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
||||||
return sessionFactory.getSessionFactoryOptions().isQueryCacheEnabled()
|
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) {
|
private static String determineCacheRegion(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
||||||
assert sessionFactory.getSessionFactoryOptions().isQueryCacheEnabled();
|
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) {
|
private static CacheMode determineCacheMode(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
||||||
assert sessionFactory.getSessionFactoryOptions().isQueryCacheEnabled();
|
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 ( setting != null ) {
|
||||||
if ( CacheMode.class.isInstance( setting ) ) {
|
if ( CacheMode.class.isInstance( setting ) ) {
|
||||||
|
@ -172,15 +179,15 @@ public class NamedQueryHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FlushMode determineFlushMode(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
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 ( setting != null ) {
|
||||||
if ( FlushMode.class.isInstance( setting ) ) {
|
if ( setting instanceof FlushMode ) {
|
||||||
return (FlushMode) setting;
|
return (FlushMode) setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( FlushModeType.class.isInstance( setting ) ) {
|
if ( setting instanceof FlushModeType ) {
|
||||||
return FlushModeTypeHelper.getFlushMode( FlushModeType.class.cast( setting ) );
|
return FlushModeTypeHelper.getFlushMode( (FlushModeType) setting );
|
||||||
}
|
}
|
||||||
|
|
||||||
final FlushMode mode = FlushMode.interpretExternalSetting( setting.toString() );
|
final FlushMode mode = FlushMode.interpretExternalSetting( setting.toString() );
|
||||||
|
@ -193,16 +200,16 @@ public class NamedQueryHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LockOptions determineLockOptions(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
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;
|
final LockMode lockMode;
|
||||||
if ( lockModeSetting == null ) {
|
if ( lockModeSetting == null ) {
|
||||||
lockMode = LockMode.NONE;
|
lockMode = LockMode.NONE;
|
||||||
}
|
}
|
||||||
else if ( LockMode.class.isInstance( lockModeSetting ) ) {
|
else if ( lockModeSetting instanceof LockMode ) {
|
||||||
lockMode = LockMode.class.cast( lockModeSetting );
|
lockMode = (LockMode) lockModeSetting;
|
||||||
}
|
}
|
||||||
else if ( LockModeType.class.isInstance( lockModeSetting ) ) {
|
else if ( lockModeSetting instanceof LockModeType ) {
|
||||||
lockMode = LockModeTypeHelper.getLockMode( LockModeType.class.cast( lockModeSetting ) );
|
lockMode = LockModeTypeHelper.getLockMode( (LockModeType) lockModeSetting );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lockMode = LockMode.fromExternalForm( lockModeSetting.toString() );
|
lockMode = LockMode.fromExternalForm( lockModeSetting.toString() );
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,10 +35,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
import org.hibernate.internal.EntityManagerMessageLogger;
|
import org.hibernate.internal.EntityManagerMessageLogger;
|
||||||
import org.hibernate.internal.HEMLogging;
|
import org.hibernate.internal.HEMLogging;
|
||||||
import org.hibernate.jpa.HibernateHints;
|
import org.hibernate.jpa.AvailableHints;
|
||||||
import org.hibernate.jpa.LegacySpecHints;
|
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.jpa.SpecHints;
|
|
||||||
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
||||||
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
|
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
|
||||||
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
|
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_LOCK_MODE;
|
||||||
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_SPACES;
|
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_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_RETRIEVE_MODE;
|
||||||
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_STORE_MODE;
|
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_STORE_MODE;
|
||||||
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH;
|
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_SCOPE;
|
||||||
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOCK_TIMEOUT;
|
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.LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT;
|
||||||
import static org.hibernate.jpa.QueryHints.HINT_NATIVE_LOCKMODE;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_CACHE_RETRIEVE_MODE;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_STORE_MODE;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_CACHE_STORE_MODE;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_FETCH_GRAPH;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_LOAD_GRAPH;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_SCOPE;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_LOCK_SCOPE;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_TIMEOUT;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_LOCK_TIMEOUT;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
|
||||||
import static org.hibernate.jpa.SpecHints.HINT_QUERY_TIMEOUT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -370,7 +367,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
||||||
|
|
||||||
@SuppressWarnings( {"UnusedDeclaration"})
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
public Set<String> getSupportedHints() {
|
public Set<String> getSupportedHints() {
|
||||||
return QueryHints.getDefinedHints();
|
return AvailableHints.getDefinedHints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -387,18 +384,18 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
protected void collectHints(Map<String, Object> hints) {
|
protected void collectHints(Map<String, Object> hints) {
|
||||||
if ( getQueryOptions().getTimeout() != null ) {
|
if ( getQueryOptions().getTimeout() != null ) {
|
||||||
hints.put( HibernateHints.HINT_TIMEOUT, getQueryOptions().getTimeout() );
|
hints.put( HINT_TIMEOUT, getQueryOptions().getTimeout() );
|
||||||
hints.put( HINT_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
|
hints.put( HINT_SPEC_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
|
||||||
hints.put( HINT_JAVAEE_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
|
hints.put( HINT_JAVAEE_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getLockOptions().getTimeOut() != WAIT_FOREVER ) {
|
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() );
|
hints.put( HINT_JAVAEE_LOCK_TIMEOUT, getLockOptions().getTimeOut() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getLockOptions().getScope() ) {
|
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() );
|
hints.put( HINT_JAVAEE_LOCK_SCOPE, getLockOptions().getScope() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,8 +414,8 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
||||||
|
|
||||||
if ( getCacheMode() != null ) {
|
if ( getCacheMode() != null ) {
|
||||||
putIfNotNull( hints, HINT_CACHE_MODE, getCacheMode() );
|
putIfNotNull( hints, HINT_CACHE_MODE, getCacheMode() );
|
||||||
putIfNotNull( hints, HINT_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
|
putIfNotNull( hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
|
||||||
putIfNotNull( hints, HINT_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
|
putIfNotNull( hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
|
||||||
putIfNotNull( hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
|
putIfNotNull( hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
|
||||||
putIfNotNull( hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
|
putIfNotNull( hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
|
||||||
}
|
}
|
||||||
|
@ -454,22 +451,22 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
||||||
|
|
||||||
boolean applied = false;
|
boolean applied = false;
|
||||||
try {
|
try {
|
||||||
if ( QueryHints.HINT_TIMEOUT.equals( hintName ) ) {
|
if ( HINT_TIMEOUT.equals( hintName ) ) {
|
||||||
applied = applyTimeoutHint( ConfigurationHelper.getInteger( value ) );
|
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 ) ) {
|
|| HINT_JAVAEE_QUERY_TIMEOUT.equals( hintName ) ) {
|
||||||
if ( 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
|
// convert milliseconds to seconds
|
||||||
int timeout = (int)Math.round( ConfigurationHelper.getInteger( value ).doubleValue() / 1000.0 );
|
int timeout = (int)Math.round( ConfigurationHelper.getInteger( value ).doubleValue() / 1000.0 );
|
||||||
applied = applyTimeoutHint( timeout );
|
applied = applyTimeoutHint( timeout );
|
||||||
}
|
}
|
||||||
else if ( HINT_LOCK_TIMEOUT.equals( hintName )
|
else if ( HINT_SPEC_LOCK_TIMEOUT.equals( hintName )
|
||||||
|| HINT_JAVAEE_LOCK_TIMEOUT.equals( hintName ) ) {
|
|| HINT_JAVAEE_LOCK_TIMEOUT.equals( hintName ) ) {
|
||||||
if ( 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 ) );
|
applied = applyLockTimeoutHint( ConfigurationHelper.getInteger( value ) );
|
||||||
}
|
}
|
||||||
|
@ -494,23 +491,23 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
||||||
else if ( HINT_CACHE_MODE.equals( hintName ) ) {
|
else if ( HINT_CACHE_MODE.equals( hintName ) ) {
|
||||||
applied = applyCacheModeHint( ConfigurationHelper.getCacheMode( value ) );
|
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 ) ) {
|
|| HINT_JAVAEE_CACHE_RETRIEVE_MODE.equals( hintName ) ) {
|
||||||
if ( 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;
|
final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf( value.toString() ) : null;
|
||||||
applied = applyJpaCacheRetrieveMode( retrieveMode );
|
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 ) ) {
|
|| HINT_JAVAEE_CACHE_STORE_MODE.equals( hintName ) ) {
|
||||||
if ( 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;
|
final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf( value.toString() ) : null;
|
||||||
applied = applyJpaCacheStoreMode( storeMode );
|
applied = applyJpaCacheStoreMode( storeMode );
|
||||||
}
|
}
|
||||||
else if ( HINT_NATIVE_LOCKMODE.equals( hintName ) ) {
|
else if ( HINT_NATIVE_LOCK_MODE.equals( hintName ) ) {
|
||||||
applied = applyNativeQueryLockMode( value );
|
applied = applyNativeQueryLockMode( value );
|
||||||
}
|
}
|
||||||
else if ( hintName.startsWith( HINT_NATIVE_LOCK_MODE ) ) {
|
else if ( hintName.startsWith( HINT_NATIVE_LOCK_MODE ) ) {
|
||||||
|
@ -527,7 +524,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
||||||
applied = false;
|
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 ) {
|
if ( value instanceof RootGraphImplementor ) {
|
||||||
applyEntityGraphQueryHint( hintName, (RootGraphImplementor<?>) value );
|
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 ) ) {
|
else if ( HINT_JAVAEE_FETCH_GRAPH.equals( hintName ) || HINT_JAVAEE_LOAD_GRAPH.equals( hintName ) ) {
|
||||||
if ( HINT_JAVAEE_FETCH_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 {
|
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 ) {
|
if ( value instanceof RootGraphImplementor ) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ import jakarta.persistence.TemporalType;
|
||||||
import jakarta.persistence.Tuple;
|
import jakarta.persistence.Tuple;
|
||||||
import jakarta.persistence.metamodel.SingularAttribute;
|
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
|
* @author Steve Ebersole
|
||||||
|
@ -1128,7 +1128,7 @@ public class NativeQueryImpl<R>
|
||||||
protected void collectHints(Map<String, Object> hints) {
|
protected void collectHints(Map<String, Object> hints) {
|
||||||
super.collectHints( hints );
|
super.collectHints( hints );
|
||||||
|
|
||||||
putIfNotNull( hints, HINT_NATIVE_LOCKMODE, getLockOptions().getLockMode() );
|
putIfNotNull( hints, HINT_NATIVE_LOCK_MODE, getLockOptions().getLockMode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1181,7 +1181,7 @@ public class NativeQueryImpl<R>
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format(
|
String.format(
|
||||||
"Native lock-mode hint [%s] must specify %s or %s. Encountered type : %s",
|
"Native lock-mode hint [%s] must specify %s or %s. Encountered type : %s",
|
||||||
HINT_NATIVE_LOCKMODE,
|
HINT_NATIVE_LOCK_MODE,
|
||||||
LockMode.class.getName(),
|
LockMode.class.getName(),
|
||||||
LockModeType.class.getName(),
|
LockModeType.class.getName(),
|
||||||
value.getClass().getName()
|
value.getClass().getName()
|
||||||
|
|
|
@ -8,15 +8,6 @@ package org.hibernate.orm.test.bytecode.enhancement.lazyCache;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
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.Cache;
|
||||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||||
|
@ -27,7 +18,6 @@ import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.graph.RootGraph;
|
import org.hibernate.graph.RootGraph;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||||
|
@ -36,7 +26,18 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
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.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.junit4.ExtraAssertions.assertTyping;
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -86,7 +87,7 @@ public class InitFromCacheTest extends BaseCoreFunctionalTestCase {
|
||||||
final RootGraph<Document> entityGraph = s.createEntityGraph( Document.class );
|
final RootGraph<Document> entityGraph = s.createEntityGraph( Document.class );
|
||||||
entityGraph.addAttributeNodes( "text", "summary" );
|
entityGraph.addAttributeNodes( "text", "summary" );
|
||||||
final Document document = s.createQuery( "from Document", Document.class )
|
final Document document = s.createQuery( "from Document", Document.class )
|
||||||
.setHint( QueryHints.JAKARTA_HINT_FETCH_GRAPH, entityGraph )
|
.setHint( HINT_SPEC_FETCH_GRAPH, entityGraph )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertTrue( isPropertyInitialized( document, "text" ) );
|
assertTrue( isPropertyInitialized( document, "text" ) );
|
||||||
assertTrue( isPropertyInitialized( document, "summary" ) );
|
assertTrue( isPropertyInitialized( document, "summary" ) );
|
||||||
|
|
|
@ -6,29 +6,28 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.immutable.entitywithmutablecollection;
|
package org.hibernate.orm.test.immutable.entitywithmutablecollection;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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.QueryException;
|
||||||
import org.hibernate.StaleObjectStateException;
|
import org.hibernate.StaleObjectStateException;
|
||||||
import org.hibernate.StaleStateException;
|
import org.hibernate.StaleStateException;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.metamodel.MappingMetamodel;
|
import org.hibernate.metamodel.MappingMetamodel;
|
||||||
import org.hibernate.query.spi.QueryImplementor;
|
|
||||||
|
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
@ -1199,7 +1198,7 @@ public abstract class AbstractEntityWithOneToManyTest {
|
||||||
CriteriaQuery<Contract> criteria = criteriaBuilder.createQuery( Contract.class );
|
CriteriaQuery<Contract> criteria = criteriaBuilder.createQuery( Contract.class );
|
||||||
criteria.from( Contract.class );
|
criteria.from( Contract.class );
|
||||||
return s.createQuery( criteria )
|
return s.createQuery( criteria )
|
||||||
.setHint( QueryHints.HINT_FETCHGRAPH, s.createEntityGraph( Contract.class ) )
|
.setHint( HINT_JAVAEE_FETCH_GRAPH, s.createEntityGraph( Contract.class ) )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1208,7 +1207,7 @@ public abstract class AbstractEntityWithOneToManyTest {
|
||||||
CriteriaQuery<ContractVariation> criteria = criteriaBuilder.createQuery( ContractVariation.class );
|
CriteriaQuery<ContractVariation> criteria = criteriaBuilder.createQuery( ContractVariation.class );
|
||||||
criteria.from( ContractVariation.class );
|
criteria.from( ContractVariation.class );
|
||||||
return s.createQuery( criteria )
|
return s.createQuery( criteria )
|
||||||
.setHint( QueryHints.HINT_FETCHGRAPH, s.createEntityGraph( ContractVariation.class ) )
|
.setHint( HINT_JAVAEE_FETCH_GRAPH, s.createEntityGraph( ContractVariation.class ) )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,7 +1216,7 @@ public abstract class AbstractEntityWithOneToManyTest {
|
||||||
CriteriaQuery<Party> criteria = criteriaBuilder.createQuery( Party.class );
|
CriteriaQuery<Party> criteria = criteriaBuilder.createQuery( Party.class );
|
||||||
criteria.from( Party.class );
|
criteria.from( Party.class );
|
||||||
return s.createQuery( criteria )
|
return s.createQuery( criteria )
|
||||||
.setHint( QueryHints.HINT_FETCHGRAPH, s.createEntityGraph( Party.class ) )
|
.setHint( HINT_JAVAEE_FETCH_GRAPH, s.createEntityGraph( Party.class ) )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
@ -34,6 +33,7 @@ import jakarta.persistence.FlushModeType;
|
||||||
import jakarta.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
import jakarta.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
|
|
||||||
|
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -507,7 +507,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
Map<String, Object> hints = new HashMap<>();
|
Map<String, Object> hints = new HashMap<>();
|
||||||
hints.put(QueryHints.HINT_READONLY, true);
|
hints.put(HINT_READ_ONLY, true);
|
||||||
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
|
|
@ -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_FETCH_SIZE;
|
||||||
import static org.hibernate.jpa.HibernateHints.HINT_FLUSH_MODE;
|
import static org.hibernate.jpa.HibernateHints.HINT_FLUSH_MODE;
|
||||||
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
|
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
|
* @author Gavin King
|
||||||
|
@ -62,7 +62,7 @@ import static org.hibernate.jpa.SpecHints.HINT_QUERY_TIMEOUT;
|
||||||
query = "select i from Item i",
|
query = "select i from Item i",
|
||||||
lockMode = LockModeType.PESSIMISTIC_WRITE,
|
lockMode = LockModeType.PESSIMISTIC_WRITE,
|
||||||
hints = {
|
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_CACHE_MODE, value = "ignore" ),
|
||||||
@QueryHint( name = HINT_CACHEABLE, value = "true" ),
|
@QueryHint( name = HINT_CACHEABLE, value = "true" ),
|
||||||
@QueryHint( name = HINT_READ_ONLY, value = "true" ),
|
@QueryHint( name = HINT_READ_ONLY, value = "true" ),
|
||||||
|
|
|
@ -11,14 +11,9 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.metamodel.CollectionClassification;
|
import org.hibernate.metamodel.CollectionClassification;
|
||||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.orm.test.jpa.graphs.Company;
|
import org.hibernate.orm.test.jpa.graphs.Company;
|
||||||
|
@ -34,7 +29,14 @@ import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
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.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.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -55,7 +57,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
entityGraph.addAttributeNodes( "location" );
|
entityGraph.addAttributeNodes( "location" );
|
||||||
entityGraph.addAttributeNodes( "markets" );
|
entityGraph.addAttributeNodes( "markets" );
|
||||||
Query query = entityManager.createQuery( "from " + Company.class.getName() );
|
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();
|
Company company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -79,7 +81,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
subSubgraph.addAttributeNodes( "friends" );
|
subSubgraph.addAttributeNodes( "friends" );
|
||||||
|
|
||||||
query = entityManager.createQuery( "from " + Company.class.getName() );
|
query = entityManager.createQuery( "from " + Company.class.getName() );
|
||||||
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
|
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
|
||||||
company = (Company) query.getSingleResult();
|
company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -121,7 +123,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
entityGraph.addAttributeNodes( "location" );
|
entityGraph.addAttributeNodes( "location" );
|
||||||
entityGraph.addAttributeNodes( "markets" );
|
entityGraph.addAttributeNodes( "markets" );
|
||||||
Query query = entityManager.createQuery( "from " + Company.class.getName() );
|
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();
|
Company company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -145,7 +147,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
subSubgraph.addAttributeNodes( "friends" );
|
subSubgraph.addAttributeNodes( "friends" );
|
||||||
|
|
||||||
query = entityManager.createQuery( "from " + Company.class.getName() );
|
query = entityManager.createQuery( "from " + Company.class.getName() );
|
||||||
query.setHint( QueryHints.HINT_FETCHGRAPH, entityGraph );
|
query.setHint( HINT_JAVAEE_FETCH_GRAPH, entityGraph );
|
||||||
company = (Company) query.getSingleResult();
|
company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -188,7 +190,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
EntityGraph<CompanyFetchProfile> entityGraph = entityManager.createEntityGraph( CompanyFetchProfile.class );
|
EntityGraph<CompanyFetchProfile> entityGraph = entityManager.createEntityGraph( CompanyFetchProfile.class );
|
||||||
entityGraph.addAttributeNodes( "markets" );
|
entityGraph.addAttributeNodes( "markets" );
|
||||||
Query query = entityManager.createQuery( "from " + CompanyFetchProfile.class.getName() );
|
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();
|
CompanyFetchProfile company = (CompanyFetchProfile) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -212,7 +214,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
subSubgraph.addAttributeNodes( "friends" );
|
subSubgraph.addAttributeNodes( "friends" );
|
||||||
|
|
||||||
query = entityManager.createQuery( "from " + CompanyFetchProfile.class.getName() );
|
query = entityManager.createQuery( "from " + CompanyFetchProfile.class.getName() );
|
||||||
query.setHint( QueryHints.HINT_FETCHGRAPH, entityGraph );
|
query.setHint( HINT_JAVAEE_FETCH_GRAPH, entityGraph );
|
||||||
company = (CompanyFetchProfile) query.getSingleResult();
|
company = (CompanyFetchProfile) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -268,7 +270,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
//entityGraph.addAttributeNodes( "location" );
|
//entityGraph.addAttributeNodes( "location" );
|
||||||
entityGraph.addAttributeNodes( "markets" );
|
entityGraph.addAttributeNodes( "markets" );
|
||||||
Query query = entityManager.createQuery( "from " + Company.class.getName() + " c order by c.location.zip, c.id" );
|
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();
|
List results = query.getResultList();
|
||||||
|
|
||||||
// - 1st will be the Company with location.zip == 11234 with an empty markets collection
|
// - 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" );
|
entityGraph.addAttributeNodes( "markets" );
|
||||||
Query query = entityManager.createQuery( "from " + Company.class.getName() + " where location.zip = :zip")
|
Query query = entityManager.createQuery( "from " + Company.class.getName() + " where location.zip = :zip")
|
||||||
.setParameter( "zip", 12345 );
|
.setParameter( "zip", 12345 );
|
||||||
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
|
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
|
||||||
Company company = (Company) query.getSingleResult();
|
Company company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -343,7 +345,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
|
|
||||||
query = entityManager.createQuery( "from " + Company.class.getName() + " where location.zip = :zip" )
|
query = entityManager.createQuery( "from " + Company.class.getName() + " where location.zip = :zip" )
|
||||||
.setParameter( "zip", 12345 );
|
.setParameter( "zip", 12345 );
|
||||||
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
|
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
|
||||||
company = (Company) query.getSingleResult();
|
company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -386,7 +388,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
// Ensure the EntityGraph and explicit fetches do not conflict.
|
// Ensure the EntityGraph and explicit fetches do not conflict.
|
||||||
Query query = entityManager.createQuery( "from " + Company.class.getName()
|
Query query = entityManager.createQuery( "from " + Company.class.getName()
|
||||||
+ " as c left join fetch c.location left join fetch c.employees" );
|
+ " 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();
|
Company company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -414,7 +416,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
Query query = entityManager.createQuery( "from " + Company.class.getName()
|
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")
|
+ " as c left join fetch c.location left join fetch c.employees where c.location.zip = :zip")
|
||||||
.setParameter("zip", 12345);
|
.setParameter("zip", 12345);
|
||||||
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
|
query.setHint( HINT_SPEC_LOAD_GRAPH, entityGraph );
|
||||||
Company company = (Company) query.getSingleResult();
|
Company company = (Company) query.getSingleResult();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -437,7 +439,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
EntityGraph<Company> entityGraph = entityManager.createEntityGraph(Company.class);
|
EntityGraph<Company> entityGraph = entityManager.createEntityGraph(Company.class);
|
||||||
entityGraph.addAttributeNodes("location");
|
entityGraph.addAttributeNodes("location");
|
||||||
Query query = entityManager.createQuery("select c from " + Company.class.getName() + " c where c.employees IS EMPTY");
|
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();
|
query.getResultList();
|
||||||
|
|
||||||
entityManager.getTransaction().commit();
|
entityManager.getTransaction().commit();
|
||||||
|
@ -479,7 +481,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
EntityGraph<?> graph = entityManager.getEntityGraph( "Student.Full" );
|
EntityGraph<?> graph = entityManager.getEntityGraph( "Student.Full" );
|
||||||
|
|
||||||
List<Student> students = entityManager.createNamedQuery( "LIST_OF_STD", Student.class )
|
List<Student> students = entityManager.createNamedQuery( "LIST_OF_STD", Student.class )
|
||||||
.setHint( QueryHints.HINT_FETCHGRAPH, graph )
|
.setHint( HINT_JAVAEE_FETCH_GRAPH, graph )
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
|
||||||
assertEquals( 2, students.size() );
|
assertEquals( 2, students.size() );
|
||||||
|
|
|
@ -25,8 +25,8 @@ import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.OracleDialect;
|
import org.hibernate.dialect.OracleDialect;
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
import org.hibernate.testing.DialectChecks;
|
import org.hibernate.testing.DialectChecks;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
import org.hibernate.testing.RequiresDialectFeature;
|
||||||
|
@ -46,6 +46,7 @@ import jakarta.persistence.PessimisticLockException;
|
||||||
import jakarta.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
import jakarta.persistence.QueryTimeoutException;
|
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.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -928,7 +929,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
"select L from Lock_ L where L.id < 10000 "
|
"select L from Lock_ L where L.id < 10000 "
|
||||||
);
|
);
|
||||||
query.setLockMode( LockModeType.PESSIMISTIC_READ );
|
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();
|
List<Lock> resultList = query.getResultList();
|
||||||
String name = resultList.get( 0 ).getName(); // force entity to be read
|
String name = resultList.get( 0 ).getName(); // force entity to be read
|
||||||
log.info( "testQueryTimeout: name read =" + name );
|
log.info( "testQueryTimeout: name read =" + name );
|
||||||
|
@ -995,7 +996,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
final CountDownLatch latch = new CountDownLatch( 1 );
|
final CountDownLatch latch = new CountDownLatch( 1 );
|
||||||
|
|
||||||
final Map<String, Object> timeoutProps = new HashMap<String, Object>();
|
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();
|
final Lock lock = new Lock();
|
||||||
|
|
||||||
FutureTask<Boolean> bgTask = new FutureTask<>(
|
FutureTask<Boolean> bgTask = new FutureTask<>(
|
||||||
|
|
|
@ -6,18 +6,19 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.jpa.lock;
|
package org.hibernate.orm.test.jpa.lock;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.dialect.CockroachDialect;
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.SkipForDialect;
|
import org.hibernate.testing.SkipForDialect;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.util.ExceptionUtil;
|
import org.hibernate.testing.util.ExceptionUtil;
|
||||||
import org.junit.Test;
|
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.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
@ -31,7 +32,7 @@ import static org.junit.Assert.fail;
|
||||||
public class NativeSQLQueryTimeoutTest extends BaseEntityManagerFunctionalTestCase {
|
public class NativeSQLQueryTimeoutTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected void addConfigOptions(Map options) {
|
protected void addConfigOptions(Map options) {
|
||||||
options.put( QueryHints.SPEC_HINT_TIMEOUT, "500" );
|
options.put( HINT_SPEC_QUERY_TIMEOUT, "500" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.hibernate.LockMode;
|
||||||
import org.hibernate.dialect.CockroachDialect;
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
import org.hibernate.internal.SessionImpl;
|
import org.hibernate.internal.SessionImpl;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.query.NativeQuery;
|
import org.hibernate.query.NativeQuery;
|
||||||
|
|
||||||
|
@ -36,6 +35,7 @@ import jakarta.persistence.criteria.JoinType;
|
||||||
import jakarta.persistence.criteria.ParameterExpression;
|
import jakarta.persistence.criteria.ParameterExpression;
|
||||||
import jakarta.persistence.criteria.Root;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -67,7 +67,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertNull( query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
assertNull( query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
||||||
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getEffectiveLockMode( "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.OPTIMISTIC, query.getLockOptions().getLockMode() );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getEffectiveLockMode( "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
|
// 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
|
// NOTE : LockModeType.READ should map to LockMode.OPTIMISTIC
|
||||||
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getLockMode() );
|
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getLockMode() );
|
||||||
assertNull( query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
assertNull( query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
||||||
assertEquals( LockMode.OPTIMISTIC, query.getLockOptions().getEffectiveLockMode( "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.OPTIMISTIC, query.getLockOptions().getLockMode() );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getAliasSpecificLockMode( "l" ) );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getEffectiveLockMode( "l" ) );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, query.getLockOptions().getEffectiveLockMode( "l" ) );
|
||||||
|
@ -180,7 +180,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Lockable reread = em.createQuery( "from Lockable l", Lockable.class )
|
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();
|
.getSingleResult();
|
||||||
assertFalse( reread.getVersion().equals( initial ) );
|
assertFalse( reread.getVersion().equals( initial ) );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
@ -233,7 +233,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Lockable reread = em.createQuery( "from Lockable l", Lockable.class )
|
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();
|
.getSingleResult();
|
||||||
assertEquals( initial, reread.getVersion() );
|
assertEquals( initial, reread.getVersion() );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
@ -315,7 +315,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Lockable reread = em.createQuery( "from Lockable l", Lockable.class )
|
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();
|
.getSingleResult();
|
||||||
assertEquals( initial, reread.getVersion() );
|
assertEquals( initial, reread.getVersion() );
|
||||||
assertTrue( em.unwrap( SessionImpl.class ).getActionQueue().hasBeforeTransactionActions() );
|
assertTrue( em.unwrap( SessionImpl.class ).getActionQueue().hasBeforeTransactionActions() );
|
||||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Map;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
@ -26,6 +25,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import jakarta.persistence.SharedCacheMode;
|
import jakarta.persistence.SharedCacheMode;
|
||||||
import jakarta.persistence.TypedQuery;
|
import jakarta.persistence.TypedQuery;
|
||||||
|
|
||||||
|
import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ public class CachedQueryTest {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
em -> {
|
em -> {
|
||||||
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
|
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();
|
List<Employee> employees = query.getResultList();
|
||||||
assertEquals( 10, employees.size() );
|
assertEquals( 10, employees.size() );
|
||||||
assertEquals( 0, stats.getQueryCacheHitCount() );
|
assertEquals( 0, stats.getQueryCacheHitCount() );
|
||||||
|
@ -109,7 +109,7 @@ public class CachedQueryTest {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
em -> {
|
em -> {
|
||||||
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
|
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();
|
List<Employee> employees = query.getResultList();
|
||||||
assertEquals( 10, employees.size() );
|
assertEquals( 10, employees.size() );
|
||||||
assertEquals( 1, stats.getQueryCacheHitCount() );
|
assertEquals( 1, stats.getQueryCacheHitCount() );
|
||||||
|
@ -133,7 +133,7 @@ public class CachedQueryTest {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
em -> {
|
em -> {
|
||||||
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
|
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();
|
List<Employee> employees = query.getResultList();
|
||||||
assertEquals( 10, employees.size() );
|
assertEquals( 10, employees.size() );
|
||||||
// query is still found in the cache
|
// query is still found in the cache
|
||||||
|
@ -164,7 +164,7 @@ public class CachedQueryTest {
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
try {
|
try {
|
||||||
TypedQuery<Employee> query = em.createQuery( "select e from Employee e", Employee.class )
|
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();
|
List<Employee> employees = query.getResultList();
|
||||||
assertEquals( 10, employees.size() );
|
assertEquals( 10, employees.size() );
|
||||||
// query is no longer found in the cache
|
// query is no longer found in the cache
|
||||||
|
|
|
@ -7,6 +7,17 @@
|
||||||
package org.hibernate.orm.test.jpa.query;
|
package org.hibernate.orm.test.jpa.query;
|
||||||
|
|
||||||
import java.util.List;
|
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.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
@ -16,17 +27,7 @@ import jakarta.persistence.NamedQueries;
|
||||||
import jakarta.persistence.NamedQuery;
|
import jakarta.persistence.NamedQuery;
|
||||||
import jakarta.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
|
||||||
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.testing.transaction.TransactionUtil.doInJPA;
|
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
|
@ -199,9 +200,9 @@ public class NamedQueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
public void testQueryHintLockMode() {
|
public void testQueryHintLockMode() {
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
Query query = entityManager.createNamedQuery( "NamedNativeQuery" );
|
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] );
|
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 ) );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package org.hibernate.orm.test.loading;
|
package org.hibernate.orm.test.loading;
|
||||||
|
|
||||||
import java.util.Collections;
|
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.TestForIssue;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
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.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
|
||||||
|
|
||||||
@DomainModel(
|
@DomainModel(
|
||||||
annotatedClasses = {
|
annotatedClasses = {
|
||||||
|
@ -42,7 +42,7 @@ public class ReadonlyHintTest {
|
||||||
@Test
|
@Test
|
||||||
void testWithReadOnlyHint(SessionFactoryScope scope) {
|
void testWithReadOnlyHint(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> {
|
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;
|
fetchedEntity.name = CHANGED_NAME;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,10 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.query;
|
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.CacheMode;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.orm.test.jpa.Distributor;
|
import org.hibernate.orm.test.jpa.Distributor;
|
||||||
import org.hibernate.orm.test.jpa.Item;
|
import org.hibernate.orm.test.jpa.Item;
|
||||||
import org.hibernate.orm.test.jpa.Wallet;
|
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.hibernate.testing.orm.junit.Jpa;
|
||||||
import org.junit.jupiter.api.Test;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
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
|
// jpa timeout is in milliseconds, whereas Hibernate's is in seconds
|
||||||
assertEquals( (Integer) 3, hibernateQuery.getTimeout() );
|
assertEquals( (Integer) 3, hibernateQuery.getTimeout() );
|
||||||
|
|
||||||
query.setHint( QueryHints.HINT_TIMEOUT, 10 );
|
query.setHint( HINT_TIMEOUT, 10 );
|
||||||
em.getEntityManagerFactory().addNamedQuery( name, query );
|
em.getEntityManagerFactory().addNamedQuery( name, query );
|
||||||
|
|
||||||
query = em.createNamedQuery( name );
|
query = em.createNamedQuery( name );
|
||||||
|
@ -189,7 +190,7 @@ public class AddNamedQueryTest {
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
||||||
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
||||||
|
|
||||||
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 10000 );
|
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 10000 );
|
||||||
em.getEntityManagerFactory().addNamedQuery( name, query );
|
em.getEntityManagerFactory().addNamedQuery( name, query );
|
||||||
|
|
||||||
query = em.createNamedQuery( name );
|
query = em.createNamedQuery( name );
|
||||||
|
|
|
@ -10,8 +10,6 @@ import java.time.LocalDate;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.hibernate.graph.GraphParser;
|
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.assertj.HibernateInitializedCondition;
|
||||||
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||||
|
@ -25,8 +23,8 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -38,7 +36,7 @@ public class QueryHintTest {
|
||||||
public void testFetchGraphHint(SessionFactoryScope scope) {
|
public void testFetchGraphHint(SessionFactoryScope scope) {
|
||||||
final Contact queried = scope.fromTransaction( (session) -> {
|
final Contact queried = scope.fromTransaction( (session) -> {
|
||||||
return session.createQuery( "from Contact", Contact.class )
|
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();
|
.uniqueResult();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ public class QueryHintTest {
|
||||||
public void testLoadGraphHint(SessionFactoryScope scope) {
|
public void testLoadGraphHint(SessionFactoryScope scope) {
|
||||||
final Contact queried = scope.fromTransaction( (session) -> {
|
final Contact queried = scope.fromTransaction( (session) -> {
|
||||||
return session.createQuery( "from Contact", Contact.class )
|
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();
|
.uniqueResult();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,10 @@ package org.hibernate.orm.test.query;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.Table;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.dialect.SybaseDialect;
|
import org.hibernate.dialect.SybaseDialect;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.jpa.QueryHints;
|
|
||||||
import org.hibernate.query.NativeQuery;
|
import org.hibernate.query.NativeQuery;
|
||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
import org.hibernate.type.descriptor.java.StringJavaType;
|
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.Before;
|
||||||
import org.junit.Test;
|
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.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
@ -111,7 +112,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
doInHibernate(
|
doInHibernate(
|
||||||
this::sessionFactory, session -> {
|
this::sessionFactory, session -> {
|
||||||
Query query = session.createQuery( QUERY );
|
Query query = session.createQuery( QUERY );
|
||||||
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 );
|
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 123000 );
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -161,7 +162,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
doInHibernate(
|
doInHibernate(
|
||||||
this::sessionFactory, session -> {
|
this::sessionFactory, session -> {
|
||||||
NativeQuery query = session.createNativeQuery( QUERY );
|
NativeQuery query = session.createNativeQuery( QUERY );
|
||||||
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 );
|
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 123000 );
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -199,7 +200,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
doInHibernate(
|
doInHibernate(
|
||||||
this::sessionFactory, session -> {
|
this::sessionFactory, session -> {
|
||||||
NativeQuery query = session.createNativeQuery( QUERY );
|
NativeQuery query = session.createNativeQuery( QUERY );
|
||||||
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 );
|
query.setHint( HINT_SPEC_QUERY_TIMEOUT, 123000 );
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -10,6 +10,17 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
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.Cacheable;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityResult;
|
import jakarta.persistence.EntityResult;
|
||||||
|
@ -19,19 +30,9 @@ import jakarta.persistence.QueryHint;
|
||||||
import jakarta.persistence.SqlResultSetMapping;
|
import jakarta.persistence.SqlResultSetMapping;
|
||||||
import jakarta.persistence.Table;
|
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.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_SPACES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -178,7 +179,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
|
||||||
|
|
||||||
checkUseCase(
|
checkUseCase(
|
||||||
tableName,
|
tableName,
|
||||||
query -> query.setHint( QueryHints.HINT_NATIVE_SPACES, tableName ),
|
query -> query.setHint( HINT_NATIVE_SPACES, tableName ),
|
||||||
// the 2 CachedEntity entries should still be there
|
// the 2 CachedEntity entries should still be there
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -203,7 +204,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
|
||||||
|
|
||||||
checkUseCase(
|
checkUseCase(
|
||||||
tableName,
|
tableName,
|
||||||
query -> query.setHint( QueryHints.HINT_NATIVE_SPACES, spaces ),
|
query -> query.setHint( HINT_NATIVE_SPACES, spaces ),
|
||||||
// the 2 CachedEntity entries should still be there
|
// the 2 CachedEntity entries should still be there
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -227,7 +228,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
|
||||||
|
|
||||||
checkUseCase(
|
checkUseCase(
|
||||||
tableName,
|
tableName,
|
||||||
query -> query.setHint( QueryHints.HINT_NATIVE_SPACES, spaces ),
|
query -> query.setHint( HINT_NATIVE_SPACES, spaces ),
|
||||||
// the 2 CachedEntity entries should still be there
|
// the 2 CachedEntity entries should still be there
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -382,7 +383,7 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
|
||||||
name = "NonCachedEntity_hint_jpa",
|
name = "NonCachedEntity_hint_jpa",
|
||||||
query = "select * from non_cached_entity",
|
query = "select * from non_cached_entity",
|
||||||
hints = {
|
hints = {
|
||||||
@QueryHint( name = QueryHints.HINT_NATIVE_SPACES, value = "non_cached_entity" )
|
@QueryHint( name = HINT_NATIVE_SPACES, value = "non_cached_entity" )
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public static class NonCachedEntity {
|
public static class NonCachedEntity {
|
||||||
|
|
Loading…
Reference in New Issue