From f826b7d5e870c8da47eaef3341574221ee7834bb Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 3 May 2016 10:39:19 -0500 Subject: [PATCH] HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (test fixup) --- .../org/hibernate/userguide/flush/AutoFlushTest.java | 9 +++++++++ .../org/hibernate/query/internal/NativeQueryImpl.java | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/documentation/src/test/java/org/hibernate/userguide/flush/AutoFlushTest.java b/documentation/src/test/java/org/hibernate/userguide/flush/AutoFlushTest.java index 52e5b90e4b..835767c43c 100644 --- a/documentation/src/test/java/org/hibernate/userguide/flush/AutoFlushTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/flush/AutoFlushTest.java @@ -9,6 +9,7 @@ package org.hibernate.userguide.flush; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; +import javax.persistence.FlushModeType; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -126,6 +127,14 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase { entityManager.persist( person ); Session session = entityManager.unwrap(Session.class); + // for this to work, the Session/EntityManager must be put into COMMIT FlushMode + // - this is a change since 5.2 to account for merging EntityManager functionality + // directly into Session. Flushing would be the JPA-spec compliant behavior, + // so we know do that by default. + session.setFlushMode( FlushModeType.COMMIT ); + // or using Hibernate's FlushMode enum + //session.setHibernateFlushMode( FlushMode.COMMIT ); + assertTrue(((Number) session .createSQLQuery( "select count(*) from Person") .uniqueResult()).intValue() == 0 ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/NativeQueryImpl.java index 4795a780fc..fac13d4b46 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/NativeQueryImpl.java @@ -239,7 +239,11 @@ public class NativeQueryImpl extends AbstractProducedQuery implements Nati effectiveFlushMode = getProducer().getHibernateFlushMode(); } - if ( effectiveFlushMode != FlushMode.MANUAL ) { + if ( effectiveFlushMode == FlushMode.ALWAYS ) { + return true; + } + + if ( effectiveFlushMode == FlushMode.AUTO ) { if ( getProducer().getFactory().getSessionFactoryOptions().isJpaBootstrap() ) { return true; }