HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (test fixup)

This commit is contained in:
Steve Ebersole 2016-05-03 10:39:19 -05:00
parent 52fd42ebb4
commit f826b7d5e8
2 changed files with 14 additions and 1 deletions

View File

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

View File

@ -239,7 +239,11 @@ public class NativeQueryImpl<T> extends AbstractProducedQuery<T> 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;
}