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() );