Fix FlushMode
This commit is contained in:
parent
1e6a601795
commit
affa6a086c
|
@ -150,6 +150,7 @@ import static org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting.det
|
|||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SessionFactoryImpl.class );
|
||||
|
@ -215,7 +216,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
|
||||
this.name = sfName;
|
||||
try {
|
||||
uuid = (String) UUID_GENERATOR.generate(null, null);
|
||||
uuid = (String) UUID_GENERATOR.generate( null, null );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AssertionFailure("Could not generate UUID");
|
||||
|
@ -349,7 +350,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
|
||||
// then construct the fetch instance...
|
||||
fetchProfile.addFetch( new Association( owner, mappingFetch.getAssociation() ), fetchStyle );
|
||||
((Loadable) owner).registerAffectingFetchProfile( fetchProfile.getName() );
|
||||
( (Loadable) owner ).registerAffectingFetchProfile( fetchProfile.getName() );
|
||||
}
|
||||
fetchProfiles.put( fetchProfile.getName(), fetchProfile );
|
||||
}
|
||||
|
@ -551,7 +552,14 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
else {
|
||||
builder.autoJoinTransactions( false );
|
||||
}
|
||||
return builder.openSession();
|
||||
|
||||
final Session session = builder.openSession();
|
||||
map.keySet().forEach ( key -> {
|
||||
if ( key instanceof String ) {
|
||||
session.setProperty( (String) key, map.get( key ) );
|
||||
}
|
||||
});
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -211,6 +211,7 @@ import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE;
|
|||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
public final class SessionImpl
|
||||
extends AbstractSessionImpl
|
||||
|
@ -294,7 +295,7 @@ public final class SessionImpl
|
|||
}
|
||||
|
||||
private void setDefaultProperties() {
|
||||
properties.putIfAbsent( AvailableSettings.FLUSH_MODE, getHibernateFlushMode() );
|
||||
properties.putIfAbsent( AvailableSettings.FLUSH_MODE, getHibernateFlushMode().name() );
|
||||
properties.putIfAbsent( JPA_LOCK_SCOPE, PessimisticLockScope.EXTENDED.name() );
|
||||
properties.putIfAbsent( JPA_LOCK_TIMEOUT, LockOptions.WAIT_FOREVER );
|
||||
properties.putIfAbsent( JPA_SHARED_CACHE_RETRIEVE_MODE, CacheModeHelper.DEFAULT_RETRIEVE_MODE );
|
||||
|
@ -315,10 +316,10 @@ public final class SessionImpl
|
|||
|
||||
protected void applyQuerySettingsAndHints(Query query) {
|
||||
if ( lockOptions.getLockMode() != LockMode.NONE ) {
|
||||
query.setLockMode( getLockMode(lockOptions.getLockMode()));
|
||||
query.setLockMode( getLockMode( lockOptions.getLockMode() ) );
|
||||
}
|
||||
Object queryTimeout;
|
||||
if ( (queryTimeout = getProperties().get(QueryHints.SPEC_HINT_TIMEOUT)) != null ) {
|
||||
if ( (queryTimeout = getProperties().get( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
|
||||
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
|
||||
}
|
||||
Object lockTimeout;
|
||||
|
@ -3172,7 +3173,7 @@ public final class SessionImpl
|
|||
}
|
||||
catch ( Exception ne ) {
|
||||
//we do not want the subsequent exception to swallow the original one
|
||||
log.unableToMarkForRollbackOnPersistenceException(ne);
|
||||
log.unableToMarkForRollbackOnPersistenceException( ne );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3687,7 +3688,7 @@ public final class SessionImpl
|
|||
applyProperties();
|
||||
}
|
||||
else {
|
||||
log.debugf("Trying to set a property which is not supported on entity manager level");
|
||||
log.debugf( "Trying to set a property which is not supported on entity manager level" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,12 +31,10 @@ import org.hibernate.FlushMode;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.hibernate.PropertyNotFoundException;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.TypeMismatchException;
|
||||
import org.hibernate.engine.query.spi.EntityGraphQueryHint;
|
||||
import org.hibernate.engine.query.spi.HQLQueryPlan;
|
||||
|
@ -63,7 +61,6 @@ import org.hibernate.query.QueryParameter;
|
|||
import org.hibernate.query.spi.QueryImplementor;
|
||||
import org.hibernate.query.spi.QueryParameterBinding;
|
||||
import org.hibernate.transform.ResultTransformer;
|
||||
import org.hibernate.type.SerializableType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.jpa.QueryHints.HINT_CACHEABLE;
|
||||
|
@ -144,7 +141,10 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
|
||||
@Override
|
||||
public FlushModeType getFlushMode() {
|
||||
return FlushModeTypeHelper.getFlushModeType( flushMode );
|
||||
return ( flushMode == null ?
|
||||
getProducer().getFlushMode() :
|
||||
FlushModeTypeHelper.getFlushModeType( flushMode )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,12 +26,11 @@ import javax.persistence.Query;
|
|||
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.jpa.AvailableSettings;
|
||||
import org.hibernate.jpa.HibernateEntityManager;
|
||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -221,8 +220,8 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
|||
EntityManager em = getOrCreateEntityManager();
|
||||
em.setFlushMode( FlushModeType.COMMIT );
|
||||
assertEquals( FlushModeType.COMMIT, em.getFlushMode() );
|
||||
( ( HibernateEntityManager ) em ).getSession().setFlushMode( FlushMode.ALWAYS );
|
||||
assertNull( em.getFlushMode() );
|
||||
( (Session) em ).setFlushMode( FlushMode.ALWAYS );
|
||||
assertEquals( em.getFlushMode(), FlushModeType.AUTO );
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue