From a9fdc1239a3a6cdacc86317f31158324fa6a3149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Thu, 12 Jul 2018 09:44:46 +0200 Subject: [PATCH] HHH-12795 Use the exact flush mode specified in @NamedQuery/@NamedNativeQuery when instantiating named queries ... instead of using an approximation in terms of JPA flush mode. --- .../java/org/hibernate/internal/SessionImpl.java | 7 +------ .../hibernate/jpa/test/query/AddNamedQueryTest.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index dca0c0a0ea..de441c2b04 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -3776,12 +3776,7 @@ public final class SessionImpl } if ( namedQueryDefinition.getFlushMode() != null ) { - if ( namedQueryDefinition.getFlushMode() == FlushMode.COMMIT ) { - query.setFlushMode( FlushModeType.COMMIT ); - } - else { - query.setFlushMode( FlushModeType.AUTO ); - } + query.setHibernateFlushMode( namedQueryDefinition.getFlushMode() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java index f46e7b9eb0..5921fa508c 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java @@ -121,7 +121,8 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase { // NOTE: here we check "query options" via the Hibernate contract (allowing nullness checking); see below for access via the JPA contract assertNull( hibernateQuery.getQueryOptions().getFirstRow() ); assertNull( hibernateQuery.getQueryOptions().getMaxRows() ); - assertEquals( FlushMode.AUTO, hibernateQuery.getHibernateFlushMode() ); + assertEquals( FlushMode.MANUAL, hibernateQuery.getHibernateFlushMode() ); + assertEquals( FlushModeType.COMMIT, hibernateQuery.getFlushMode() ); assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() ); assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() ); // jpa timeout is in milliseconds, whereas Hibernate's is in seconds @@ -137,7 +138,8 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase { // NOTE: here we check "query options" via the JPA contract assertEquals( 0, hibernateQuery.getFirstResult() ); assertEquals( Integer.MAX_VALUE, hibernateQuery.getMaxResults() ); - assertEquals( FlushModeType.AUTO, hibernateQuery.getFlushMode() ); + assertEquals( FlushMode.MANUAL, hibernateQuery.getHibernateFlushMode() ); + assertEquals( FlushModeType.COMMIT, hibernateQuery.getFlushMode() ); assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() ); assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() ); assertEquals( (Integer) 10, hibernateQuery.getTimeout() ); @@ -150,7 +152,8 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase { // assert the state of the query config settings based on the initial named query assertEquals( 0, hibernateQuery.getFirstResult() ); assertEquals( Integer.MAX_VALUE, hibernateQuery.getMaxResults() ); - assertEquals( FlushModeType.AUTO, hibernateQuery.getFlushMode() ); + assertEquals( FlushMode.MANUAL, hibernateQuery.getHibernateFlushMode() ); + assertEquals( FlushModeType.COMMIT, hibernateQuery.getFlushMode() ); assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() ); assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() ); assertEquals( (Integer) 10, hibernateQuery.getTimeout() ); @@ -163,7 +166,8 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase { // assert the state of the query config settings based on the initial named query assertEquals( 51, hibernateQuery.getFirstResult() ); assertEquals( Integer.MAX_VALUE, hibernateQuery.getMaxResults() ); - assertEquals( FlushModeType.AUTO, hibernateQuery.getFlushMode() ); + assertEquals( FlushMode.MANUAL, hibernateQuery.getHibernateFlushMode() ); + assertEquals( FlushModeType.COMMIT, hibernateQuery.getFlushMode() ); assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() ); assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() ); assertEquals( (Integer) 10, hibernateQuery.getTimeout() );