Skip to content

Commit

Permalink
HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager i…
Browse files Browse the repository at this point in the history
…nto hibernate-core (test fixup)
  • Loading branch information
sebersole committed May 6, 2016
1 parent 52fd42e commit f826b7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -9,6 +9,7 @@
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

Expand Down Expand Up @@ -126,6 +127,14 @@ public void testFlushAutoSQLNativeSession() {
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 );
Expand Down
Expand Up @@ -239,7 +239,11 @@ private boolean shouldFlush() {
effectiveFlushMode = getProducer().getHibernateFlushMode();
}

if ( effectiveFlushMode != FlushMode.MANUAL ) {
if ( effectiveFlushMode == FlushMode.ALWAYS ) {
return true;
}

if ( effectiveFlushMode == FlushMode.AUTO ) {
if ( getProducer().getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
return true;
}
Expand Down

0 comments on commit f826b7d

Please sign in to comment.