mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-19 17:45:10 +00:00
HHH-8949 @QueryHint( name="javax.persistence.cache.retrieveMode", value="<valid value>") does not work
This commit is contained in:
parent
75706dafda
commit
80fd1c96e6
@ -315,28 +315,14 @@ else if ( HINT_FLUSH_MODE.equals( hintName ) ) {
|
|||||||
applied = applyFlushModeHint( ConfigurationHelper.getFlushMode( value ) );
|
applied = applyFlushModeHint( ConfigurationHelper.getFlushMode( value ) );
|
||||||
}
|
}
|
||||||
else if ( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE.equals( hintName ) ) {
|
else if ( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE.equals( hintName ) ) {
|
||||||
final CacheRetrieveMode retrieveMode = (CacheRetrieveMode) value;
|
final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf( value.toString() ) : null;
|
||||||
|
final CacheStoreMode storeMode = getHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.class );
|
||||||
CacheStoreMode storeMode = hints != null
|
|
||||||
? (CacheStoreMode) hints.get( AvailableSettings.SHARED_CACHE_STORE_MODE )
|
|
||||||
: null;
|
|
||||||
if ( storeMode == null ) {
|
|
||||||
storeMode = (CacheStoreMode) entityManager.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE );
|
|
||||||
}
|
|
||||||
applied = applyCacheModeHint( CacheModeHelper.interpretCacheMode( storeMode, retrieveMode ) );
|
applied = applyCacheModeHint( CacheModeHelper.interpretCacheMode( storeMode, retrieveMode ) );
|
||||||
}
|
}
|
||||||
else if ( AvailableSettings.SHARED_CACHE_STORE_MODE.equals( hintName ) ) {
|
else if ( AvailableSettings.SHARED_CACHE_STORE_MODE.equals( hintName ) ) {
|
||||||
final CacheStoreMode storeMode = (CacheStoreMode) value;
|
final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf( value.toString () ) : null;
|
||||||
|
final CacheRetrieveMode retrieveMode = getHint( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE, CacheRetrieveMode.class );
|
||||||
CacheRetrieveMode retrieveMode = hints != null
|
applied = applyCacheModeHint( CacheModeHelper.interpretCacheMode( storeMode, retrieveMode ) );
|
||||||
? (CacheRetrieveMode) hints.get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE )
|
|
||||||
: null;
|
|
||||||
if ( retrieveMode == null ) {
|
|
||||||
retrieveMode = (CacheRetrieveMode) entityManager.getProperties().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE );
|
|
||||||
}
|
|
||||||
applied = applyCacheModeHint(
|
|
||||||
CacheModeHelper.interpretCacheMode( storeMode, retrieveMode )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else if ( QueryHints.HINT_NATIVE_LOCKMODE.equals( hintName ) ) {
|
else if ( QueryHints.HINT_NATIVE_LOCKMODE.equals( hintName ) ) {
|
||||||
if ( !isNativeSqlQuery() ) {
|
if ( !isNativeSqlQuery() ) {
|
||||||
@ -411,6 +397,16 @@ else if ( HINT_FETCHGRAPH.equals( hintName ) || HINT_LOADGRAPH.equals( hintName
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T extends Enum<T>> T getHint(String key, Class<T> hintClass) {
|
||||||
|
Object hint = hints != null ? hints.get( key ) : null;
|
||||||
|
|
||||||
|
if ( hint == null ) {
|
||||||
|
hint = entityManager.getProperties().get( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
return hint != null ? Enum.valueOf( hintClass, hint.toString() ) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the query represented here a native SQL query?
|
* Is the query represented here a native SQL query?
|
||||||
*
|
*
|
||||||
|
@ -30,11 +30,7 @@
|
|||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Parameter;
|
|
||||||
import javax.persistence.Query;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.persistence.Tuple;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -189,6 +185,34 @@ public void testMultipleParameterLists() throws Exception {
|
|||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH_8949" )
|
||||||
|
public void testCacheStoreAndRetrieveModeParameter() throws Exception {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
Query query = em.createQuery( "select item from Item item" );
|
||||||
|
|
||||||
|
query.getHints().clear();
|
||||||
|
|
||||||
|
query.setHint( "javax.persistence.cache.retrieveMode", CacheRetrieveMode.USE );
|
||||||
|
query.setHint( "javax.persistence.cache.storeMode", CacheStoreMode.REFRESH );
|
||||||
|
|
||||||
|
assertEquals( CacheRetrieveMode.USE, query.getHints().get( "javax.persistence.cache.retrieveMode" ) );
|
||||||
|
assertEquals( CacheStoreMode.REFRESH, query.getHints().get( "javax.persistence.cache.storeMode" ) );
|
||||||
|
|
||||||
|
query.getHints().clear();
|
||||||
|
|
||||||
|
query.setHint( "javax.persistence.cache.retrieveMode", "USE" );
|
||||||
|
query.setHint( "javax.persistence.cache.storeMode", "REFRESH" );
|
||||||
|
|
||||||
|
assertEquals( "USE", query.getHints().get( "javax.persistence.cache.retrieveMode" ) );
|
||||||
|
assertEquals( "REFRESH", query.getHints().get( "javax.persistence.cache.storeMode" ) );
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJpaPositionalParameters() {
|
public void testJpaPositionalParameters() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user