From b4cfe7e54a7e58544f1f321d67bda70c8cd1d376 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Sun, 28 Nov 2021 17:09:35 +0100 Subject: [PATCH] Fix readOnly value and Query#scroll() --- .../JdbcSelectExecutorStandardImpl.java | 156 +- .../entity/AbstractEntityInitializer.java | 9 +- .../test/readonly/AbstractReadOnlyTest.java | 2 +- .../{ => orm}/test/readonly/Container.java | 2 +- .../{ => orm}/test/readonly/Course.java | 2 +- .../{ => orm}/test/readonly/DataPoint.hbm.xml | 2 +- .../{ => orm}/test/readonly/DataPoint.java | 2 +- .../{ => orm}/test/readonly/Enrolment.hbm.xml | 2 +- .../{ => orm}/test/readonly/Enrolment.java | 2 +- .../{ => orm}/test/readonly/Info.java | 2 +- .../{ => orm}/test/readonly/Owner.java | 2 +- .../orm/test/readonly/ReadOnlyProxyTest.java | 1593 ++++++++++------- .../ReadOnlySessionLazyNonLazyTest.java | 7 +- .../test/readonly/ReadOnlySessionTest.java | 6 +- .../orm/test/readonly/ReadOnlyTest.java | 7 +- .../readonly/ReadOnlyVersionedNodesTest.java | 4 +- .../{ => orm}/test/readonly/Student.java | 2 +- .../{ => orm}/test/readonly/StudentDTO.java | 2 +- .../test/readonly/TextHolder.hbm.xml | 2 +- .../{ => orm}/test/readonly/TextHolder.java | 2 +- .../test/readonly/VersionedNode.hbm.xml | 2 +- .../test/readonly/VersionedNode.java | 2 +- 22 files changed, 1097 insertions(+), 715 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/AbstractReadOnlyTest.java (98%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/Container.java (98%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/Course.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/DataPoint.hbm.xml (98%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/DataPoint.java (97%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/Enrolment.hbm.xml (95%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/Enrolment.java (97%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/Info.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/Owner.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/ReadOnlySessionTest.java (99%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/Student.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/StudentDTO.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/TextHolder.hbm.xml (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/TextHolder.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/VersionedNode.hbm.xml (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/readonly/VersionedNode.java (96%) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcSelectExecutorStandardImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcSelectExecutorStandardImpl.java index c3e080d568..9f5aad18dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcSelectExecutorStandardImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcSelectExecutorStandardImpl.java @@ -18,6 +18,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; import org.hibernate.CacheMode; +import org.hibernate.FlushMode; import org.hibernate.LockOptions; import org.hibernate.ScrollMode; import org.hibernate.cache.spi.QueryKey; @@ -25,11 +26,17 @@ import org.hibernate.cache.spi.QueryResultsCache; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.graph.spi.AppliedGraph; import org.hibernate.internal.util.collections.ArrayHelper; +import org.hibernate.query.Limit; +import org.hibernate.query.ResultListTransformer; import org.hibernate.query.TupleTransformer; import org.hibernate.query.internal.ScrollableResultsIterator; +import org.hibernate.query.spi.QueryOptions; +import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.spi.ScrollableResultsImplementor; import org.hibernate.sql.exec.SqlExecLogger; +import org.hibernate.sql.exec.spi.Callback; import org.hibernate.sql.exec.spi.ExecutionContext; import org.hibernate.sql.exec.spi.JdbcParameterBindings; import org.hibernate.sql.exec.spi.JdbcSelect; @@ -58,6 +65,9 @@ import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.type.BasicType; import org.hibernate.type.descriptor.java.JavaType; +import jakarta.persistence.CacheRetrieveMode; +import jakarta.persistence.CacheStoreMode; + /** * @author Steve Ebersole */ @@ -104,7 +114,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor { RowTransformer rowTransformer) { final SharedSessionContractImplementor session = executionContext.getSession(); session.autoFlushIfRequired( jdbcSelect.getAffectedTableNames() ); - return executeQuery( + return executeQueryScroll( jdbcSelect, jdbcParameterBindings, executionContext, @@ -169,6 +179,150 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor { } } } + + private T executeQueryScroll( + JdbcSelect jdbcSelect, + JdbcParameterBindings jdbcParameterBindings, + ExecutionContext executionContext, + RowTransformer rowTransformer, + Function statementCreator, + ResultsConsumer resultsConsumer) { + return doExecuteQuery( + jdbcSelect, + jdbcParameterBindings, + getScrollContext( executionContext, executionContext.getSession().getPersistenceContext() ), + rowTransformer, + statementCreator, + resultsConsumer + ); + } + + /* + When `Query#scroll()` is call the query is not executed immediately, a new ExecutionContext with the values of the `persistenceContext.isDefaultReadOnly()` and of the `queryOptions.isReadOnly()` + set at the moment of the Query#scroll() call is created in order to use it when the query will be executed. + */ + private ExecutionContext getScrollContext(ExecutionContext context, PersistenceContext persistenceContext) { + final QueryOptions queryOptions = context.getQueryOptions(); + final Boolean readOnly; + if ( queryOptions.isReadOnly() == null ) { + readOnly = persistenceContext.isDefaultReadOnly(); + } + else { + readOnly = queryOptions.isReadOnly(); + } + final Integer timeout = queryOptions.getTimeout(); + final FlushMode flushMode = queryOptions.getFlushMode(); + final AppliedGraph appliedGraph = queryOptions.getAppliedGraph(); + final TupleTransformer tupleTransformer = queryOptions.getTupleTransformer(); + final ResultListTransformer resultListTransformer = queryOptions.getResultListTransformer(); + final Boolean resultCachingEnabled = queryOptions.isResultCachingEnabled(); + final CacheRetrieveMode cacheRetrieveMode = queryOptions.getCacheRetrieveMode(); + final CacheStoreMode cacheStoreMode = queryOptions.getCacheStoreMode(); + final String resultCacheRegionName = queryOptions.getResultCacheRegionName(); + final LockOptions lockOptions = queryOptions.getLockOptions(); + final String comment = queryOptions.getComment(); + final List databaseHints = queryOptions.getDatabaseHints(); + final Integer fetchSize = queryOptions.getFetchSize(); + final Limit limit = queryOptions.getLimit(); + + return new ExecutionContext() { + @Override + public QueryOptions getQueryOptions() { + + return new QueryOptions() { + @Override + public Integer getTimeout() { + return timeout; + } + + @Override + public FlushMode getFlushMode() { + return flushMode; + } + + @Override + public Boolean isReadOnly() { + return readOnly; + } + + @Override + public AppliedGraph getAppliedGraph() { + return appliedGraph; + } + + @Override + public TupleTransformer getTupleTransformer() { + return tupleTransformer; + } + + @Override + public ResultListTransformer getResultListTransformer() { + return resultListTransformer; + } + + @Override + public Boolean isResultCachingEnabled() { + return resultCachingEnabled; + } + + @Override + public CacheRetrieveMode getCacheRetrieveMode() { + return cacheRetrieveMode; + } + + @Override + public CacheStoreMode getCacheStoreMode() { + return cacheStoreMode; + } + + @Override + public String getResultCacheRegionName() { + return resultCacheRegionName; + } + + @Override + public LockOptions getLockOptions() { + return lockOptions; + } + + @Override + public String getComment() { + return comment; + } + + @Override + public List getDatabaseHints() { + return databaseHints; + } + + @Override + public Integer getFetchSize() { + return fetchSize; + } + + @Override + public Limit getLimit() { + return limit; + } + }; + } + + @Override + public QueryParameterBindings getQueryParameterBindings() { + return context.getQueryParameterBindings(); + } + + @Override + public Callback getCallback() { + return context.getCallback(); + } + + @Override + public SharedSessionContractImplementor getSession() { + return context.getSession(); + } + }; + } private T doExecuteQuery( JdbcSelect jdbcSelect, JdbcParameterBindings jdbcParameterBindings, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java index a4210d1f0f..fae33690e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java @@ -872,13 +872,8 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces private boolean isReadOnly( RowProcessingState rowProcessingState, SharedSessionContractImplementor persistenceContext) { - if ( persistenceContext.isDefaultReadOnly() ) { - return true; - } - - final Boolean queryOption = rowProcessingState.getJdbcValuesSourceProcessingState().getQueryOptions().isReadOnly(); - - return queryOption == null ? false : queryOption; + final Boolean readOnly = rowProcessingState.getQueryOptions().isReadOnly(); + return readOnly == null ? persistenceContext.isDefaultReadOnly() : readOnly; } private void preLoad(RowProcessingState rowProcessingState) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/AbstractReadOnlyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/AbstractReadOnlyTest.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/AbstractReadOnlyTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/AbstractReadOnlyTest.java index a290ae710f..bed550feda 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/AbstractReadOnlyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/AbstractReadOnlyTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import org.hibernate.CacheMode; import org.hibernate.cfg.AvailableSettings; diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/Container.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Container.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/Container.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Container.java index cbb98cb77d..70a74df09d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/Container.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Container.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import java.io.Serializable; import java.util.HashSet; import java.util.Set; diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/Course.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Course.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/Course.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Course.java index c016918087..87226c5746 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/Course.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Course.java @@ -6,7 +6,7 @@ */ //$Id: Course.java 5686 2005-02-12 07:27:32Z steveebersole $ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/DataPoint.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/DataPoint.hbm.xml similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/DataPoint.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/DataPoint.hbm.xml index 598ecd463a..6772060e3a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/DataPoint.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/DataPoint.hbm.xml @@ -10,7 +10,7 @@ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + package="org.hibernate.orm.test.readonly"> diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/DataPoint.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/DataPoint.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/DataPoint.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/DataPoint.java index 1081eed36c..beabd6a82a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/DataPoint.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/DataPoint.java @@ -6,7 +6,7 @@ */ //$Id: DataPoint.java 7231 2005-06-19 22:04:00Z oneovthafew $ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import java.io.Serializable; import java.math.BigDecimal; diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/Enrolment.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Enrolment.hbm.xml similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/Enrolment.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Enrolment.hbm.xml index d827a54a20..d5a845b5ce 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/Enrolment.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Enrolment.hbm.xml @@ -9,7 +9,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/Enrolment.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Enrolment.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/Enrolment.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Enrolment.java index ebe15f3cca..5451bf18ee 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/Enrolment.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Enrolment.java @@ -6,7 +6,7 @@ */ //$Id: Enrolment.java 6970 2005-05-31 20:24:41Z oneovthafew $ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import java.io.Serializable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/Info.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Info.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/Info.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Info.java index 19e9aae5ae..5417e0fa86 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/Info.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Info.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/Owner.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Owner.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/Owner.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Owner.java index dbba877e55..f16ce5c196 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/Owner.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Owner.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import java.io.Serializable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyProxyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyProxyTest.java index 97860b5000..1b57ca2feb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyProxyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyProxyTest.java @@ -21,8 +21,6 @@ import org.hibernate.proxy.LazyInitializer; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.test.readonly.AbstractReadOnlyTest; -import org.hibernate.test.readonly.DataPoint; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,8 +38,8 @@ import static org.junit.jupiter.api.Assertions.fail; */ @DomainModel( xmlMappings = { - "org/hibernate/test/readonly/DataPoint.hbm.xml", - "org/hibernate/test/readonly/TextHolder.hbm.xml" + "org/hibernate/orm/test/readonly/DataPoint.hbm.xml", + "org/hibernate/orm/test/readonly/TextHolder.hbm.xml" } ) public class ReadOnlyProxyTest extends AbstractReadOnlyTest { @@ -50,533 +48,704 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { public void testReadOnlyViaSessionDoesNotInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.setReadOnly( dp, false ); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.flush(); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.getTransaction().commit(); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.setReadOnly( dp, false ); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.flush(); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.getTransaction().commit(); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaLazyInitializerDoesNotInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - dpLI.setReadOnly( true ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - dpLI.setReadOnly( false ); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.flush(); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.getTransaction().commit(); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + dpLI.setReadOnly( true ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + dpLI.setReadOnly( false ); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.flush(); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.getTransaction().commit(); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaSessionNoChangeAfterInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - Hibernate.initialize( dp ); - assertTrue( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + Hibernate.initialize( dp ); + assertTrue( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - Hibernate.initialize( dp ); - assertTrue( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, true ); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + Hibernate.initialize( dp ); + assertTrue( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, true ); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.setReadOnly( dp, false ); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - Hibernate.initialize( dp ); - assertTrue( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.setReadOnly( dp, false ); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + Hibernate.initialize( dp ); + assertTrue( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaLazyInitializerNoChangeAfterInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - checkReadOnly( s, dp, false ); - assertTrue( dpLI.isUninitialized() ); - Hibernate.initialize( dp ); - assertFalse( dpLI.isUninitialized() ); - checkReadOnly( s, dp, false ); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + checkReadOnly( session, dp, false ); + assertTrue( dpLI.isUninitialized() ); + Hibernate.initialize( dp ); + assertFalse( dpLI.isUninitialized() ); + checkReadOnly( session, dp, false ); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - dpLI.setReadOnly( true ); - checkReadOnly( s, dp, true ); - assertTrue( dpLI.isUninitialized() ); - Hibernate.initialize( dp ); - assertFalse( dpLI.isUninitialized() ); - checkReadOnly( s, dp, true ); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + dpLI.setReadOnly( true ); + checkReadOnly( session, dp, true ); + assertTrue( dpLI.isUninitialized() ); + Hibernate.initialize( dp ); + assertFalse( dpLI.isUninitialized() ); + checkReadOnly( session, dp, true ); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - dpLI.setReadOnly( true ); - checkReadOnly( s, dp, true ); - assertTrue( dpLI.isUninitialized() ); - dpLI.setReadOnly( false ); - checkReadOnly( s, dp, false ); - assertTrue( dpLI.isUninitialized() ); - Hibernate.initialize( dp ); - assertFalse( dpLI.isUninitialized() ); - checkReadOnly( s, dp, false ); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + dpLI.setReadOnly( true ); + checkReadOnly( session, dp, true ); + assertTrue( dpLI.isUninitialized() ); + dpLI.setReadOnly( false ); + checkReadOnly( session, dp, false ); + assertTrue( dpLI.isUninitialized() ); + Hibernate.initialize( dp ); + assertFalse( dpLI.isUninitialized() ); + checkReadOnly( session, dp, false ); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaSessionBeforeInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - s.setReadOnly( dp, true ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - checkReadOnly( s, dp, true ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + session.setReadOnly( dp, true ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + checkReadOnly( session, dp, true ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testModifiableViaSessionBeforeInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - checkReadOnly( s, dp, false ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + checkReadOnly( session, dp, false ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaSessionBeforeInitByModifiableQuery(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - assertFalse( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - DataPoint dpFromQuery = (DataPoint) s.createQuery( "from DataPoint where id=" + dpOrig.getId() ).setReadOnly( - false ).uniqueResult(); - assertTrue( Hibernate.isInitialized( dpFromQuery ) ); - assertSame( dp, dpFromQuery ); - checkReadOnly( s, dp, true ); - dp.setDescription( "changed" ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + assertFalse( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + DataPoint dpFromQuery = (DataPoint) session.createQuery( "from DataPoint where id=" + dpOrig.getId() ) + .setReadOnly( + false ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( dpFromQuery ) ); + assertSame( dp, dpFromQuery ); + checkReadOnly( session, dp, true ); + dp.setDescription( "changed" ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaSessionBeforeInitByReadOnlyQuery(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - assertFalse( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - DataPoint dpFromQuery = (DataPoint) s.createQuery( "from DataPoint where id=" + dpOrig.getId() ).setReadOnly( - true ).uniqueResult(); - assertTrue( Hibernate.isInitialized( dpFromQuery ) ); - assertSame( dp, dpFromQuery ); - checkReadOnly( s, dp, true ); - dp.setDescription( "changed" ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + assertFalse( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + DataPoint dpFromQuery = (DataPoint) session.createQuery( "from DataPoint where id=" + dpOrig.getId() ) + .setReadOnly( + true ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( dpFromQuery ) ); + assertSame( dp, dpFromQuery ); + checkReadOnly( session, dp, true ); + dp.setDescription( "changed" ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testModifiableViaSessionBeforeInitByModifiableQuery(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - assertFalse( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - DataPoint dpFromQuery = (DataPoint) s.createQuery( "from DataPoint where id=" + dpOrig.getId() ).setReadOnly( - false ).uniqueResult(); - assertTrue( Hibernate.isInitialized( dpFromQuery ) ); - assertSame( dp, dpFromQuery ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + assertFalse( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + DataPoint dpFromQuery = (DataPoint) session.createQuery( "from DataPoint where id=" + dpOrig.getId() ) + .setReadOnly( + false ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( dpFromQuery ) ); + assertSame( dp, dpFromQuery ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testModifiableViaSessionBeforeInitByReadOnlyQuery(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - DataPoint dpFromQuery = (DataPoint) s.createQuery( "from DataPoint where id=" + dpOrig.getId() ).setReadOnly( - true ).uniqueResult(); - assertTrue( Hibernate.isInitialized( dpFromQuery ) ); - assertSame( dp, dpFromQuery ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + DataPoint dpFromQuery = (DataPoint) session.createQuery( "from DataPoint where id=" + dpOrig.getId() ) + .setReadOnly( + true ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( dpFromQuery ) ); + assertSame( dp, dpFromQuery ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaLazyInitializerBeforeInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - assertTrue( dpLI.isUninitialized() ); - checkReadOnly( s, dp, false ); - dpLI.setReadOnly( true ); - checkReadOnly( s, dp, true ); - dp.setDescription( "changed" ); - assertFalse( dpLI.isUninitialized() ); - assertEquals( "changed", dp.getDescription() ); - checkReadOnly( s, dp, true ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + assertTrue( dpLI.isUninitialized() ); + checkReadOnly( session, dp, false ); + dpLI.setReadOnly( true ); + checkReadOnly( session, dp, true ); + dp.setDescription( "changed" ); + assertFalse( dpLI.isUninitialized() ); + assertEquals( "changed", dp.getDescription() ); + checkReadOnly( session, dp, true ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testModifiableViaLazyInitializerBeforeInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - assertTrue( dp instanceof HibernateProxy ); - assertTrue( dpLI.isUninitialized() ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertFalse( dpLI.isUninitialized() ); - assertEquals( "changed", dp.getDescription() ); - checkReadOnly( s, dp, false ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + assertTrue( dp instanceof HibernateProxy ); + assertTrue( dpLI.isUninitialized() ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertFalse( dpLI.isUninitialized() ); + assertEquals( "changed", dp.getDescription() ); + checkReadOnly( session, dp, false ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyViaLazyInitializerAfterInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - assertTrue( dpLI.isUninitialized() ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertFalse( dpLI.isUninitialized() ); - assertEquals( "changed", dp.getDescription() ); - checkReadOnly( s, dp, false ); - dpLI.setReadOnly( true ); - checkReadOnly( s, dp, true ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + assertTrue( dpLI.isUninitialized() ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertFalse( dpLI.isUninitialized() ); + assertEquals( "changed", dp.getDescription() ); + checkReadOnly( session, dp, false ); + dpLI.setReadOnly( true ); + checkReadOnly( session, dp, true ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testModifiableViaLazyInitializerAfterInit(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); - assertTrue( dpLI.isUninitialized() ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertFalse( dpLI.isUninitialized() ); - assertEquals( "changed", dp.getDescription() ); - checkReadOnly( s, dp, false ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + LazyInitializer dpLI = ( (HibernateProxy) dp ).getHibernateLazyInitializer(); + assertTrue( dpLI.isUninitialized() ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertFalse( dpLI.isUninitialized() ); + assertEquals( "changed", dp.getDescription() ); + checkReadOnly( session, dp, false ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + } + ); + + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test @@ -584,45 +753,59 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { public void testModifyToReadOnlyToModifiableIsUpdated(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - assertFalse( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - s.setReadOnly( dp, false ); - checkReadOnly( s, dp, false ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + assertFalse( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + session.setReadOnly( dp, false ); + checkReadOnly( session, dp, false ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - try { - assertEquals( "changed", dp.getDescription() ); - // should fail due to HHH-4642 - } - finally { - s.getTransaction().rollback(); - s.close(); - s = openSession( scope ); - s.beginTransaction(); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); - } + scope.inSession( + session -> { + session.beginTransaction(); + try { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + + assertEquals( "changed", dp.getDescription() ); + // should fail due to HHH-4642 + } + finally { + session.getTransaction().rollback(); + } + } + ); + + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + session.delete( dp ); + } + ); } @Test @@ -630,213 +813,273 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { public void testReadOnlyModifiedToModifiableIsUpdated(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - assertFalse( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - s.setReadOnly( dp, false ); - checkReadOnly( s, dp, false ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + assertFalse( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + session.setReadOnly( dp, false ); + checkReadOnly( session, dp, false ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - try { - assertEquals( "changed", dp.getDescription() ); - // should fail due to HHH-4642 - } - finally { - s.getTransaction().rollback(); - s.close(); - s = openSession( scope ); - s.beginTransaction(); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); - } + scope.inSession( + session -> { + session.beginTransaction(); + try { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + + assertEquals( "changed", dp.getDescription() ); + // should fail due to HHH-4642 + } + finally { + session.getTransaction().rollback(); + } + } + ); + + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyChangedEvictedUpdate(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - assertFalse( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - s.evict( dp ); - assertFalse( s.contains( dp ) ); - s.update( dp ); - checkReadOnly( s, dp, false ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + assertFalse( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + session.evict( dp ); + assertFalse( session.contains( dp ) ); + session.update( dp ); + checkReadOnly( session, dp, false ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + } + ); + + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyToModifiableInitWhenModifiedIsUpdated(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - s.setReadOnly( dp, false ); - checkReadOnly( s, dp, false ); - assertFalse( Hibernate.isInitialized( dp ) ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + session.setReadOnly( dp, false ); + checkReadOnly( session, dp, false ); + assertFalse( Hibernate.isInitialized( dp ) ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyInitToModifiableModifiedIsUpdated(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - Hibernate.initialize( dp ); - assertTrue( Hibernate.isInitialized( dp ) ); - checkReadOnly( s, dp, true ); - s.setReadOnly( dp, false ); - checkReadOnly( s, dp, false ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + Hibernate.initialize( dp ); + assertTrue( Hibernate.isInitialized( dp ) ); + checkReadOnly( session, dp, true ); + session.setReadOnly( dp, false ); + checkReadOnly( session, dp, false ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( "changed", dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( "changed", dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyModifiedUpdate(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - dp.setDescription( "changed" ); - assertTrue( Hibernate.isInitialized( dp ) ); - assertEquals( "changed", dp.getDescription() ); - checkReadOnly( s, dp, true ); - s.update( dp ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + dp.setDescription( "changed" ); + assertTrue( Hibernate.isInitialized( dp ) ); + assertEquals( "changed", dp.getDescription() ); + checkReadOnly( session, dp, true ); + session.update( dp ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertEquals( dpOrig.getId(), dp.getId() ); - assertEquals( dpOrig.getDescription(), dp.getDescription() ); - assertEquals( dpOrig.getX(), dp.getX() ); - assertEquals( dpOrig.getY(), dp.getY() ); - s.delete( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertEquals( dpOrig.getId(), dp.getId() ); + assertEquals( dpOrig.getDescription(), dp.getDescription() ); + assertEquals( dpOrig.getX(), dp.getX() ); + assertEquals( dpOrig.getY(), dp.getY() ); + session.delete( dp ); + } + ); } @Test public void testReadOnlyDelete(SessionFactoryScope scope) { DataPoint dpOrig = createDataPoint( CacheMode.IGNORE, scope ); - Session s = openSession( scope ); - s.setCacheMode( CacheMode.IGNORE ); - s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); - assertTrue( dp instanceof HibernateProxy ); - checkReadOnly( s, dp, false ); - s.setReadOnly( dp, true ); - checkReadOnly( s, dp, true ); - assertFalse( Hibernate.isInitialized( dp ) ); - s.delete( dp ); - s.flush(); - s.getTransaction().commit(); - s.close(); + scope.inSession( + session -> { + session.setCacheMode( CacheMode.IGNORE ); + session.beginTransaction(); + try { + DataPoint dp = session.load( DataPoint.class, dpOrig.getId() ); + assertTrue( dp instanceof HibernateProxy ); + checkReadOnly( session, dp, false ); + session.setReadOnly( dp, true ); + checkReadOnly( session, dp, true ); + assertFalse( Hibernate.isInitialized( dp ) ); + session.delete( dp ); + session.flush(); + session.getTransaction().commit(); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); - s = openSession( scope ); - s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); - assertNull( dp ); - s.getTransaction().commit(); - s.close(); + scope.inTransaction( + session -> { + DataPoint dp = session.get( DataPoint.class, dpOrig.getId() ); + assertNull( dp ); + } + ); } @Test @@ -855,7 +1098,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); t = s.beginTransaction(); - dp = (DataPoint) s.load( DataPoint.class, dp.getId() ); + dp = s.load( DataPoint.class, dp.getId() ); s.setReadOnly( dp, true ); assertFalse( Hibernate.isInitialized( dp ) ); s.refresh( dp ); @@ -876,7 +1119,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.clear(); t = s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dp.getId() ); + dp = s.get( DataPoint.class, dp.getId() ); assertEquals( "original", dp.getDescription() ); s.delete( dp ); t.commit(); @@ -907,7 +1150,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); t = s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dp.getId() ); + dp = s.get( DataPoint.class, dp.getId() ); s.delete( dp ); s.flush(); try { @@ -925,7 +1168,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); t = s.beginTransaction(); s.setCacheMode( CacheMode.IGNORE ); - DataPoint dpProxyInit = (DataPoint) s.load( DataPoint.class, dp.getId() ); + DataPoint dpProxyInit = s.load( DataPoint.class, dp.getId() ); assertEquals( "original", dp.getDescription() ); s.delete( dpProxyInit ); t.commit(); @@ -981,7 +1224,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); t = s.beginTransaction(); - dp = (DataPoint) s.load( DataPoint.class, dp.getId() ); + dp = s.load( DataPoint.class, dp.getId() ); assertFalse( Hibernate.isInitialized( dp ) ); assertFalse( s.isReadOnly( dp ) ); s.setReadOnly( dp, true ); @@ -1002,7 +1245,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.clear(); t = s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dp.getId() ); + dp = s.get( DataPoint.class, dp.getId() ); assertEquals( "original", dp.getDescription() ); s.delete( dp ); t.commit(); @@ -1016,7 +1259,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { Session s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); checkReadOnly( s, dp, false ); assertFalse( Hibernate.isInitialized( dp ) ); @@ -1031,7 +1274,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dpLoaded = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dpLoaded = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dpLoaded instanceof HibernateProxy ); checkReadOnly( s, dpLoaded, false ); s.setReadOnly( dpLoaded, true ); @@ -1065,7 +1308,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { Session s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); checkReadOnly( s, dp, false ); assertFalse( Hibernate.isInitialized( dp ) ); @@ -1080,7 +1323,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dpLoaded = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dpLoaded = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dpLoaded instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dpLoaded ) ); Hibernate.initialize( dpLoaded ); @@ -1098,7 +1341,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); + dp = s.get( DataPoint.class, dpOrig.getId() ); assertEquals( dpOrig.getId(), dp.getId() ); assertEquals( dpOrig.getDescription(), dp.getDescription() ); assertEquals( dpOrig.getX(), dp.getX() ); @@ -1115,7 +1358,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { Session s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); checkReadOnly( s, dp, false ); assertFalse( Hibernate.isInitialized( dp ) ); @@ -1131,7 +1374,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dpLoaded = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dpLoaded = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dpLoaded instanceof HibernateProxy ); checkReadOnly( s, dpLoaded, false ); s.setReadOnly( dpLoaded, true ); @@ -1148,7 +1391,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); + dp = s.get( DataPoint.class, dpOrig.getId() ); assertEquals( dpOrig.getId(), dp.getId() ); assertEquals( dpOrig.getDescription(), dp.getDescription() ); assertEquals( dpOrig.getX(), dp.getX() ); @@ -1165,7 +1408,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { Session s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); checkReadOnly( s, dp, false ); assertFalse( Hibernate.isInitialized( dp ) ); @@ -1181,7 +1424,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dpLoaded = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dpLoaded = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dpLoaded instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dpLoaded ) ); Hibernate.initialize( dpLoaded ); @@ -1199,7 +1442,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); + dp = s.get( DataPoint.class, dpOrig.getId() ); assertEquals( dpOrig.getId(), dp.getId() ); assertEquals( dpOrig.getDescription(), dp.getDescription() ); assertEquals( dpOrig.getX(), dp.getX() ); @@ -1216,7 +1459,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { Session s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); checkReadOnly( s, dp, false ); assertFalse( Hibernate.isInitialized( dp ) ); @@ -1231,7 +1474,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dpEntity = (DataPoint) s.get( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dpEntity = s.get( DataPoint.class, dpOrig.getId() ); assertFalse( dpEntity instanceof HibernateProxy ); assertFalse( s.isReadOnly( dpEntity ) ); s.setReadOnly( dpEntity, true ); @@ -1246,7 +1489,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); + dp = s.get( DataPoint.class, dpOrig.getId() ); assertEquals( dpOrig.getId(), dp.getId() ); assertEquals( dpOrig.getDescription(), dp.getDescription() ); assertEquals( dpOrig.getX(), dp.getX() ); @@ -1264,7 +1507,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1290,7 +1533,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); + dp = s.get( DataPoint.class, dpOrig.getId() ); assertEquals( dpOrig.getId(), dp.getId() ); assertEquals( dpOrig.getDescription(), dp.getDescription() ); assertEquals( dpOrig.getX(), dp.getX() ); @@ -1308,7 +1551,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1334,7 +1577,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s = openSession( scope ); s.beginTransaction(); - dp = (DataPoint) s.get( DataPoint.class, dpOrig.getId() ); + dp = s.get( DataPoint.class, dpOrig.getId() ); assertEquals( dpOrig.getId(), dp.getId() ); assertEquals( "changed", dp.getDescription() ); assertEquals( dpOrig.getX(), dp.getX() ); @@ -1468,7 +1711,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1500,7 +1743,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1530,7 +1773,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1562,7 +1805,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1596,7 +1839,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1631,7 +1874,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); @@ -1663,7 +1906,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest { s.setCacheMode( CacheMode.IGNORE ); s.beginTransaction(); - DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long( dpOrig.getId() ) ); + DataPoint dp = s.load( DataPoint.class, dpOrig.getId() ); assertTrue( dp instanceof HibernateProxy ); assertFalse( Hibernate.isInitialized( dp ) ); checkReadOnly( s, dp, false ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlySessionLazyNonLazyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlySessionLazyNonLazyTest.java index 193a67212b..8ec535e009 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlySessionLazyNonLazyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlySessionLazyNonLazyTest.java @@ -20,11 +20,6 @@ import org.hibernate.proxy.HibernateProxy; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.test.readonly.AbstractReadOnlyTest; -import org.hibernate.test.readonly.Container; -import org.hibernate.test.readonly.DataPoint; -import org.hibernate.test.readonly.Info; -import org.hibernate.test.readonly.Owner; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -56,7 +51,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * @author Gail Badner */ @DomainModel( - xmlMappings = { "org/hibernate/test/readonly/DataPoint.hbm.xml" } + xmlMappings = { "org/hibernate/orm/test/readonly/DataPoint.hbm.xml" } ) public class ReadOnlySessionLazyNonLazyTest extends AbstractReadOnlyTest { diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/ReadOnlySessionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlySessionTest.java similarity index 99% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/ReadOnlySessionTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlySessionTest.java index d7ed76bf58..de51a1fdf0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/ReadOnlySessionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlySessionTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import java.math.BigDecimal; import java.util.List; @@ -34,8 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ @DomainModel( xmlMappings = { - "org/hibernate/test/readonly/DataPoint.hbm.xml", - "org/hibernate/test/readonly/TextHolder.hbm.xml" + "org/hibernate/orm/test/readonly/DataPoint.hbm.xml", + "org/hibernate/orm/test/readonly/TextHolder.hbm.xml" } ) public class ReadOnlySessionTest extends AbstractReadOnlyTest { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyTest.java index 0118ea0c41..49c116891c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyTest.java @@ -17,9 +17,6 @@ import org.hibernate.Transaction; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.test.readonly.AbstractReadOnlyTest; -import org.hibernate.test.readonly.DataPoint; -import org.hibernate.test.readonly.TextHolder; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,8 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ @DomainModel( xmlMappings = { - "org/hibernate/test/readonly/DataPoint.hbm.xml", - "org/hibernate/test/readonly/TextHolder.hbm.xml" + "org/hibernate/orm/test/readonly/DataPoint.hbm.xml", + "org/hibernate/orm/test/readonly/TextHolder.hbm.xml" } ) public class ReadOnlyTest extends AbstractReadOnlyTest { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyVersionedNodesTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyVersionedNodesTest.java index 2b74660c70..06d705c11c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyVersionedNodesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/ReadOnlyVersionedNodesTest.java @@ -9,8 +9,6 @@ package org.hibernate.orm.test.readonly; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.test.readonly.AbstractReadOnlyTest; -import org.hibernate.test.readonly.VersionedNode; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -23,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertSame; * @author Gail Badner */ @DomainModel( - xmlMappings = "org/hibernate/test/readonly/VersionedNode.hbm.xml" + xmlMappings = "org/hibernate/orm/test/readonly/VersionedNode.hbm.xml" ) public class ReadOnlyVersionedNodesTest extends AbstractReadOnlyTest { diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/Student.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Student.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/Student.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Student.java index b96a520936..91220468f0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/Student.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/Student.java @@ -6,7 +6,7 @@ */ //$Id: Student.java 9116 2006-01-23 21:21:01Z steveebersole $ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import java.util.HashSet; import java.util.Set; diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/StudentDTO.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/StudentDTO.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/StudentDTO.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/StudentDTO.java index af856d63d0..454b20c23f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/StudentDTO.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/StudentDTO.java @@ -9,7 +9,7 @@ * Created on 28-Jan-2005 * */ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/TextHolder.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/TextHolder.hbm.xml similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/TextHolder.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/TextHolder.hbm.xml index c2ad10947e..01027a3492 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/TextHolder.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/TextHolder.hbm.xml @@ -9,7 +9,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/TextHolder.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/TextHolder.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/TextHolder.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/TextHolder.java index f1ea103cb4..a5af1e3ac3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/TextHolder.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/TextHolder.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/VersionedNode.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/VersionedNode.hbm.xml similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/VersionedNode.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/VersionedNode.hbm.xml index 7e56906380..062544febb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/VersionedNode.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/VersionedNode.hbm.xml @@ -9,7 +9,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/readonly/VersionedNode.java b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/VersionedNode.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/readonly/VersionedNode.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/readonly/VersionedNode.java index 40255d11af..f5c750bbce 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/readonly/VersionedNode.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/readonly/VersionedNode.java @@ -7,7 +7,7 @@ //$Id: $ -package org.hibernate.test.readonly; +package org.hibernate.orm.test.readonly; import java.util.HashSet; import java.util.Set;