diff --git a/documentation/src/test/java/org/hibernate/userguide/flush/ManualFlushTest.java b/documentation/src/test/java/org/hibernate/userguide/flush/ManualFlushTest.java index 287a2d6a0a..b5d0f454aa 100644 --- a/documentation/src/test/java/org/hibernate/userguide/flush/ManualFlushTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/flush/ManualFlushTest.java @@ -25,7 +25,6 @@ import org.junit.Test; import org.jboss.logging.Logger; import static org.hibernate.userguide.util.TransactionUtil.doInJPA; - import static org.junit.Assert.assertTrue; /** @@ -56,7 +55,7 @@ public class ManualFlushTest extends BaseEntityManagerFunctionalTestCase { entityManager.persist(person); Session session = entityManager.unwrap( Session.class); - session.setFlushMode( FlushMode.MANUAL); + session.setHibernateFlushMode( FlushMode.MANUAL ); assertTrue(((Number) entityManager .createQuery("select count(id) from Person") diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java index e448da1f19..7bc337dfc2 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java @@ -419,6 +419,7 @@ public class ProcedureCallImpl ); try { + LOG.debugf( "Preparing procedure call : %s", call ); final CallableStatement statement = (CallableStatement) getSession() .getJdbcCoordinator() .getStatementPreparer() @@ -596,7 +597,7 @@ public class ProcedureCallImpl getProducer().checkOpen( true ); try { - registerParameter( (ParameterRegistrationImplementor) registerParameter( position, type, mode ) ); + registerParameter( position, type, mode ); } catch (HibernateException he) { throw getExceptionConverter().convert( he ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java index dc26c8e9ba..9e746fe1f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java @@ -123,7 +123,7 @@ public interface QueryProducer { * * @see javax.persistence.EntityManager#createNativeQuery(String,Class) */ - NativeQuery createNativeQuery(String sqlString, Class resultClass); + NativeQuery createNativeQuery(String sqlString, Class resultClass); /** * Create a NativeQuery instance for the given native (SQL) query using diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java index 2ef2adc7a8..32afbdde4e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java @@ -115,6 +115,9 @@ public abstract class AbstractProducedQuery implements QueryImplementor { this.producer = producer; this.parameterMetadata = parameterMetadata; this.queryParameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() ); + +// this.flushMode = producer.getHibernateFlushMode(); +// this.cacheMode = producer.getCacheMode(); } @Override 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 5f71903af8..9b387cc23b 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 @@ -224,10 +224,24 @@ public class NativeQueryImpl extends AbstractProducedQuery implements Nati // apps, so we only do the flush if a transaction is in progress. // // NOTE : this was added for JPA initially. Perhaps we want to only do this from JPA usage? - if ( getProducer().isTransactionInProgress() ) { + if ( shouldFlush() ) { getProducer().flush(); } + } + private boolean shouldFlush() { + if ( getProducer().isTransactionInProgress() ) { + FlushMode effectiveFlushMode = getHibernateFlushMode(); + if ( effectiveFlushMode == null ) { + effectiveFlushMode = getProducer().getHibernateFlushMode(); + } + + if ( effectiveFlushMode != FlushMode.MANUAL ) { + return true; + } + } + + return false; } protected int doExecuteUpdate() { diff --git a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java index a54e577bac..fb14ffd06d 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java @@ -14,7 +14,6 @@ import java.sql.SQLException; import org.hibernate.ConnectionAcquisitionMode; import org.hibernate.ConnectionReleaseMode; -import org.hibernate.HibernateException; import org.hibernate.ResourceClosedException; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; @@ -58,8 +57,11 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple this.observer = jdbcSessionContext.getObserver(); this.resourceRegistry = resourceRegistry; - this.connectionHandlingMode = jdbcSessionContext.getPhysicalConnectionHandlingMode(); - validateConnectionHandlingMode( connectionHandlingMode, jdbcConnectionAccess ); + this.connectionHandlingMode = determineConnectionHandlingMode( + jdbcSessionContext.getPhysicalConnectionHandlingMode(), + jdbcConnectionAccess + + ); this.sqlExceptionHelper = jdbcSessionContext.getServiceRegistry() .getService( JdbcServices.class ) @@ -70,18 +72,15 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple } } - private void validateConnectionHandlingMode( + private PhysicalConnectionHandlingMode determineConnectionHandlingMode( PhysicalConnectionHandlingMode connectionHandlingMode, JdbcConnectionAccess jdbcConnectionAccess) { - if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ) { - // make sure the Connection access supports reacquisition... - // NOTE we used to just swap it here with a more correct release-mode, but - // really this ought to be validated at a higher level... - if ( !jdbcConnectionAccess.supportsAggressiveRelease() ) { - throw new HibernateException( - "Connection provider reports to not support aggressive release, but ATER_STATEMENT releasing was requested" ); - } + if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT + && !jdbcConnectionAccess.supportsAggressiveRelease() ) { + return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION; } + + return connectionHandlingMode; } private LogicalConnectionManagedImpl(