Fixes for Yoann's search + 6.0 tracking

query-options - null cache-mode
This commit is contained in:
Steve Ebersole 2021-07-29 13:28:41 -05:00
parent a716b348f7
commit 8362ce72ba
2 changed files with 36 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import javax.persistence.CacheStoreMode;
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.query.QueryLogging;
import org.hibernate.query.ResultListTransformer;
import org.hibernate.query.TupleTransformer;
@ -37,6 +38,11 @@ public interface MutableQueryOptions extends QueryOptions {
* Corollary to {@link #getCacheMode()}
*/
default void setCacheMode(CacheMode cacheMode) {
if ( cacheMode == null ) {
QueryLogging.QUERY_LOGGER.debug( "Null CacheMode passed to #setCacheMode; falling back to `NORMAL`" );
cacheMode = CacheMode.NORMAL;
}
setCacheRetrieveMode( cacheMode.getJpaRetrieveMode() );
setCacheStoreMode( cacheMode.getJpaStoreMode() );
}

View File

@ -0,0 +1,30 @@
/*
* 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.orm.test.query.options;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
/**
* @author Steve Ebersole
*/
@DomainModel( standardModels = StandardDomainModel.CONTACTS )
@SessionFactory
public class CacheModeTests {
@Test
public void testNullCacheMode(SessionFactoryScope scope) {
// tests passing null as CacheMode
scope.inTransaction( (session) -> {
session.createQuery( "select c from Contact c" )
.setCacheMode( null )
.list();
});
}
}