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