Fix wrong creation of new instances for non aggregated id with no IdClass
This commit is contained in:
parent
9080872946
commit
15e49692e9
|
@ -86,6 +86,15 @@ public abstract class AbstractCompositeIdentifierMapping
|
|||
.appendContainer( EntityIdentifierMapping.ROLE_LOCAL_NAME );
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the identifier have a corresponding EmbeddableId or IdClass?
|
||||
*
|
||||
* @return false if there is not an IdCass or an EmbeddableId
|
||||
*/
|
||||
public boolean hasContainingClass(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddableMappingType getMappedType() {
|
||||
return embeddableDescriptor;
|
||||
|
|
|
@ -73,8 +73,13 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif
|
|||
|
||||
@Override
|
||||
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
|
||||
final Serializable disassemble = bootCidDescriptor.getType().disassemble( entity, session, null );
|
||||
return bootIdClassDescriptor.getType().assemble( disassemble, session, null );
|
||||
if ( hasContainingClass() ) {
|
||||
final Serializable disassemble = bootCidDescriptor.getType().disassemble( entity, session, null );
|
||||
return bootIdClassDescriptor.getType().assemble( disassemble, session, null );
|
||||
}
|
||||
else {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,4 +151,8 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif
|
|||
return idAttributeMappings.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainingClass() {
|
||||
return bootIdClassDescriptor != bootCidDescriptor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
|||
|
||||
final RowProcessingStateStandardImpl rowProcessingState = new RowProcessingStateStandardImpl(
|
||||
valuesProcessingState,
|
||||
executionContext.getQueryOptions(),
|
||||
executionContext,
|
||||
rowReader,
|
||||
jdbcValues
|
||||
);
|
||||
|
|
|
@ -183,11 +183,10 @@ public abstract class AbstractImmediateCollectionInitializer extends AbstractCol
|
|||
}
|
||||
}
|
||||
|
||||
final PluralAttributeMapping collectionAttributeMapping = getCollectionAttributeMapping();
|
||||
final CollectionPersister collectionDescriptor = collectionAttributeMapping.getCollectionDescriptor();
|
||||
final CollectionSemantics collectionSemantics = collectionDescriptor.getCollectionSemantics();
|
||||
|
||||
if ( collectionInstance == null && collectionKey != null ) {
|
||||
final CollectionPersister collectionDescriptor = getCollectionAttributeMapping().getCollectionDescriptor();
|
||||
final CollectionSemantics collectionSemantics = collectionDescriptor.getCollectionSemantics();
|
||||
|
||||
collectionInstance = collectionSemantics.instantiateWrapper(
|
||||
collectionKey.getKey(),
|
||||
getInitializingCollectionDescriptor(),
|
||||
|
@ -260,30 +259,14 @@ public abstract class AbstractImmediateCollectionInitializer extends AbstractCol
|
|||
return;
|
||||
}
|
||||
|
||||
resolveKeyCollectionValue( rowProcessingState );
|
||||
|
||||
final CollectionKey loadingKey = rowProcessingState.getCollectionKey();
|
||||
if ( loadingKey != null ) {
|
||||
if ( loadingKey != null && loadingKey.getRole().equals( getCollectionAttributeMapping().getNavigableRole().getNavigableName() ) ) {
|
||||
collectionKey = loadingKey;
|
||||
return;
|
||||
}
|
||||
|
||||
final JdbcValuesSourceProcessingOptions processingOptions = rowProcessingState.getJdbcValuesSourceProcessingState()
|
||||
.getProcessingOptions();
|
||||
|
||||
keyContainerValue = keyContainerAssembler.assemble(
|
||||
rowProcessingState,
|
||||
processingOptions
|
||||
);
|
||||
|
||||
if ( keyCollectionAssembler == null || keyContainerAssembler == keyCollectionAssembler ) {
|
||||
keyCollectionValue = keyContainerValue;
|
||||
}
|
||||
else {
|
||||
keyCollectionValue = keyCollectionAssembler.assemble(
|
||||
rowProcessingState,
|
||||
processingOptions
|
||||
);
|
||||
}
|
||||
|
||||
Object keyContainerValue = getKeyContainerValue();
|
||||
if ( keyContainerValue != null ) {
|
||||
this.collectionKey = new CollectionKey(
|
||||
|
@ -325,6 +308,26 @@ public abstract class AbstractImmediateCollectionInitializer extends AbstractCol
|
|||
}
|
||||
}
|
||||
|
||||
private void resolveKeyCollectionValue(RowProcessingState rowProcessingState) {
|
||||
final JdbcValuesSourceProcessingOptions processingOptions = rowProcessingState.getJdbcValuesSourceProcessingState()
|
||||
.getProcessingOptions();
|
||||
|
||||
keyContainerValue = keyContainerAssembler.assemble(
|
||||
rowProcessingState,
|
||||
processingOptions
|
||||
);
|
||||
|
||||
if ( keyCollectionAssembler == null || keyContainerAssembler == keyCollectionAssembler ) {
|
||||
keyCollectionValue = keyContainerValue;
|
||||
}
|
||||
else {
|
||||
keyCollectionValue = keyCollectionAssembler.assemble(
|
||||
rowProcessingState,
|
||||
processingOptions
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of the container/owner side of the collection key (FK). Identifies the
|
||||
* owner of the collection
|
||||
|
|
|
@ -43,13 +43,16 @@ public class DelayedCollectionInitializer extends AbstractCollectionInitializer
|
|||
|
||||
@Override
|
||||
public void resolveKey(RowProcessingState rowProcessingState) {
|
||||
super.resolveKey( rowProcessingState );
|
||||
if ( collectionKey != null ) {
|
||||
// already resolved
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final CollectionKey loadingKey = rowProcessingState.getCollectionKey();
|
||||
if ( loadingKey != null ) {
|
||||
if ( loadingKey != null && loadingKey.getRole()
|
||||
.equals( getCollectionAttributeMapping().getNavigableRole().getNavigableName() ) ) {
|
||||
collectionKey = loadingKey;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.sql.results.graph.embeddable.internal;
|
||||
|
||||
import org.hibernate.metamodel.internal.AbstractCompositeIdentifierMapping;
|
||||
import org.hibernate.sql.results.graph.embeddable.EmbeddableInitializer;
|
||||
import org.hibernate.sql.results.graph.DomainResultAssembler;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
|
||||
|
@ -16,11 +17,18 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EmbeddableAssembler implements DomainResultAssembler {
|
||||
private final EmbeddableInitializer initializer;
|
||||
|
||||
protected final EmbeddableInitializer initializer;
|
||||
private final boolean containingClass;
|
||||
|
||||
public EmbeddableAssembler(EmbeddableInitializer initializer) {
|
||||
this.initializer = initializer;
|
||||
if ( initializer instanceof AbstractCompositeIdentifierMapping ) {
|
||||
containingClass = ( (AbstractCompositeIdentifierMapping) initializer.getInitializedPart() )
|
||||
.hasContainingClass();
|
||||
}
|
||||
else {
|
||||
containingClass = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +36,10 @@ public class EmbeddableAssembler implements DomainResultAssembler {
|
|||
return initializer.getInitializedPart().getJavaTypeDescriptor();
|
||||
}
|
||||
|
||||
public boolean hasContainingClass() {
|
||||
return containingClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object assemble(RowProcessingState rowProcessingState, JdbcValuesSourceProcessingOptions options) {
|
||||
initializer.resolveKey( rowProcessingState );
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.hibernate.sql.results.graph.DomainResult;
|
|||
import org.hibernate.sql.results.graph.DomainResultAssembler;
|
||||
import org.hibernate.sql.results.graph.Fetch;
|
||||
import org.hibernate.sql.results.graph.Initializer;
|
||||
import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableAssembler;
|
||||
import org.hibernate.sql.results.internal.NullValueAssembler;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
|
||||
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
|
||||
|
@ -73,6 +74,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
private final List<Initializer> identifierInitializers = new ArrayList<>();
|
||||
|
||||
private final DomainResultAssembler identifierAssembler;
|
||||
private final boolean embeddableIdentifierWithNoContainingClass;
|
||||
private final DomainResultAssembler discriminatorAssembler;
|
||||
private final DomainResultAssembler versionAssembler;
|
||||
private final DomainResultAssembler<Object> rowIdAssembler;
|
||||
|
@ -81,7 +83,6 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
|
||||
// per-row state
|
||||
private EntityPersister concreteDescriptor;
|
||||
private Object entityIdentifier;
|
||||
private EntityKey entityKey;
|
||||
private Object entityInstance;
|
||||
private boolean missing;
|
||||
|
@ -99,7 +100,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
DomainResult<?> versionResult,
|
||||
DomainResult<Object> rowIdResult,
|
||||
AssemblerCreationState creationState) {
|
||||
super( );
|
||||
super();
|
||||
|
||||
this.referencedModelPart = resultDescriptor.getEntityValuedModelPart();
|
||||
this.entityDescriptor = (EntityPersister) referencedModelPart.getEntityMappingType();
|
||||
|
@ -159,6 +160,8 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
this.identifierAssembler = null;
|
||||
}
|
||||
|
||||
embeddableIdentifierWithNoContainingClass = hasEmbeddableIdentifierWithNoContainingClass( identifierAssembler );
|
||||
|
||||
if ( discriminatorResult != null ) {
|
||||
discriminatorAssembler = discriminatorResult.createResultAssembler( creationState );
|
||||
}
|
||||
|
@ -197,7 +200,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
final DomainResultAssembler stateAssembler;
|
||||
if ( fetch == null ) {
|
||||
stateAssembler = new NullValueAssembler(
|
||||
attributeMapping.getMappedType() .getMappedJavaTypeDescriptor()
|
||||
attributeMapping.getMappedType().getMappedJavaTypeDescriptor()
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -210,8 +213,15 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
);
|
||||
}
|
||||
|
||||
protected final boolean hasEmbeddableIdentifierWithNoContainingClass(DomainResultAssembler identifierAssembler) {
|
||||
if ( identifierAssembler instanceof EmbeddableAssembler ) {
|
||||
return !( (EmbeddableAssembler) identifierAssembler ).hasContainingClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelPart getInitializedPart(){
|
||||
public ModelPart getInitializedPart() {
|
||||
return referencedModelPart;
|
||||
}
|
||||
|
||||
|
@ -290,7 +300,6 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
return;
|
||||
}
|
||||
|
||||
initializeIdentifier( rowProcessingState );
|
||||
resolveEntityKey( rowProcessingState );
|
||||
|
||||
if ( entityKey == null ) {
|
||||
|
@ -334,10 +343,10 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
|
||||
final EntityPersister concreteType = session.getFactory().getMetamodel().findEntityDescriptor( concreteEntityName );
|
||||
|
||||
if ( concreteType == null || ! concreteType.isTypeOrSuperType( entityDescriptor ) ) {
|
||||
if ( concreteType == null || !concreteType.isTypeOrSuperType( entityDescriptor ) ) {
|
||||
throw new WrongClassException(
|
||||
concreteEntityName,
|
||||
entityIdentifier,
|
||||
null,
|
||||
entityDescriptor.getEntityName(),
|
||||
discriminatorValue
|
||||
);
|
||||
|
@ -349,29 +358,6 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
return concreteType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected void initializeIdentifier(RowProcessingState rowProcessingState) {
|
||||
if ( EntityLoadingLogger.TRACE_ENABLED ) {
|
||||
EntityLoadingLogger.LOGGER.tracef(
|
||||
"(%s) Beginning Initializer#initializeIdentifier process for entity (%s) ",
|
||||
StringHelper.collapse( this.getClass().getName() ),
|
||||
getNavigablePath()
|
||||
);
|
||||
}
|
||||
|
||||
identifierInitializers.forEach( initializer -> initializer.resolveKey( rowProcessingState ) );
|
||||
identifierInitializers.forEach( initializer -> initializer.resolveInstance( rowProcessingState ) );
|
||||
identifierInitializers.forEach( initializer -> initializer.initializeInstance( rowProcessingState ) );
|
||||
|
||||
if ( EntityLoadingLogger.TRACE_ENABLED ) {
|
||||
EntityLoadingLogger.LOGGER.tracef(
|
||||
"(%s) Fiish Initializer#initializeIdentifier process for entity (%s) ",
|
||||
StringHelper.collapse( this.getClass().getName() ),
|
||||
getNavigablePath()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected void resolveEntityKey(RowProcessingState rowProcessingState) {
|
||||
if ( entityKey != null ) {
|
||||
|
@ -388,6 +374,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
id = jdbcValuesSourceProcessingState.getProcessingOptions().getEffectiveOptionalId();
|
||||
}
|
||||
else {
|
||||
initializeIdentifier( rowProcessingState );
|
||||
id = identifierAssembler.assemble(
|
||||
rowProcessingState,
|
||||
jdbcValuesSourceProcessingState.getProcessingOptions()
|
||||
|
@ -399,6 +386,11 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
// EARLY EXIT!!!
|
||||
return;
|
||||
}
|
||||
|
||||
if ( embeddableIdentifierWithNoContainingClass ) {
|
||||
entityInstance = id;
|
||||
}
|
||||
|
||||
// 2) build the EntityKey
|
||||
this.entityKey = new EntityKey( id, concreteDescriptor );
|
||||
|
||||
|
@ -414,6 +406,31 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected void initializeIdentifier(RowProcessingState rowProcessingState) {
|
||||
if ( EntityLoadingLogger.TRACE_ENABLED ) {
|
||||
EntityLoadingLogger.LOGGER.tracef(
|
||||
"(%s) Beginning Initializer#initializeIdentifier process for entity (%s) ",
|
||||
StringHelper.collapse( this.getClass().getName() ),
|
||||
getNavigablePath()
|
||||
);
|
||||
}
|
||||
|
||||
if ( !embeddableIdentifierWithNoContainingClass ) {
|
||||
identifierInitializers.forEach( initializer -> initializer.resolveKey( rowProcessingState ) );
|
||||
identifierInitializers.forEach( initializer -> initializer.resolveInstance( rowProcessingState ) );
|
||||
identifierInitializers.forEach( initializer -> initializer.initializeInstance( rowProcessingState ) );
|
||||
}
|
||||
|
||||
if ( EntityLoadingLogger.TRACE_ENABLED ) {
|
||||
EntityLoadingLogger.LOGGER.tracef(
|
||||
"(%s) Fiish Initializer#initializeIdentifier process for entity (%s) ",
|
||||
StringHelper.collapse( this.getClass().getName() ),
|
||||
getNavigablePath()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveInstance(RowProcessingState rowProcessingState) {
|
||||
if ( missing ) {
|
||||
|
|
|
@ -8,11 +8,13 @@ package org.hibernate.sql.results.internal;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.engine.spi.CollectionKey;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.spi.QueryOptions;
|
||||
import org.hibernate.query.spi.QueryParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.Callback;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.results.graph.Initializer;
|
||||
import org.hibernate.sql.results.graph.entity.EntityFetch;
|
||||
import org.hibernate.sql.results.jdbc.internal.JdbcValuesSourceProcessingStateStandardImpl;
|
||||
|
@ -28,20 +30,20 @@ public class RowProcessingStateStandardImpl implements RowProcessingState {
|
|||
private static final Initializer[] NO_INITIALIZERS = new Initializer[0];
|
||||
|
||||
private final JdbcValuesSourceProcessingStateStandardImpl resultSetProcessingState;
|
||||
private final QueryOptions queryOptions;
|
||||
|
||||
private final Initializer[] initializers;
|
||||
|
||||
private final RowReader<?> rowReader;
|
||||
private final JdbcValues jdbcValues;
|
||||
private final ExecutionContext executionContext;
|
||||
|
||||
public RowProcessingStateStandardImpl(
|
||||
JdbcValuesSourceProcessingStateStandardImpl resultSetProcessingState,
|
||||
QueryOptions queryOptions,
|
||||
ExecutionContext executionContext,
|
||||
RowReader<?> rowReader,
|
||||
JdbcValues jdbcValues) {
|
||||
this.resultSetProcessingState = resultSetProcessingState;
|
||||
this.queryOptions = queryOptions;
|
||||
this.executionContext = executionContext;
|
||||
this.rowReader = rowReader;
|
||||
this.jdbcValues = jdbcValues;
|
||||
|
||||
|
@ -113,7 +115,7 @@ public class RowProcessingStateStandardImpl implements RowProcessingState {
|
|||
|
||||
@Override
|
||||
public QueryOptions getQueryOptions() {
|
||||
return queryOptions;
|
||||
return executionContext.getQueryOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,6 +128,11 @@ public class RowProcessingStateStandardImpl implements RowProcessingState {
|
|||
return afterLoadAction -> {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionKey getCollectionKey() {
|
||||
return executionContext.getCollectionKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Initializer resolveInitializer(NavigablePath path) {
|
||||
for ( Initializer initializer : initializers ) {
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id: Contract.java 7222 2005-06-19 17:22:01Z oneovthafew $
|
||||
package org.hibernate.test.immutable;
|
||||
package org.hibernate.orm.test.immutable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -84,7 +85,7 @@ public class Contract implements Serializable {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public List getVariations() {
|
||||
public List<ContractVariation> getVariations() {
|
||||
return variations;
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.immutable">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.immutable">
|
||||
<class name="Info" mutable="true">
|
||||
<id name="id">
|
||||
<generator class="increment"/>
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: ContractVariation.java 7222 2005-06-19 17:22:01Z oneovthafew $
|
||||
package org.hibernate.test.immutable;
|
||||
package org.hibernate.orm.test.immutable;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.immutable;
|
||||
package org.hibernate.orm.test.immutable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
@ -13,31 +13,34 @@ import javax.persistence.criteria.CriteriaQuery;
|
|||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
|
||||
import org.hibernate.type.TextType;
|
||||
import org.hibernate.type.descriptor.jdbc.ClobTypeDescriptor;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||
import org.hibernate.testing.orm.junit.DialectContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
||||
public class ImmutableTest extends BaseSessionFactoryFunctionalTest {
|
||||
|
||||
private static class TextAsMaterializedClobType extends AbstractSingleColumnStandardBasicType<String> {
|
||||
public final static TextAsMaterializedClobType INSTANCE = new TextAsMaterializedClobType();
|
||||
|
||||
|
@ -51,17 +54,22 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
if ( Oracle8iDialect.class.isInstance( getDialect() ) ) {
|
||||
cfg.registerTypeOverride( TextAsMaterializedClobType.INSTANCE );
|
||||
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
Dialect dialect = DialectContext.getDialect();
|
||||
if ( OracleDialect.class.isInstance( dialect ) ) {
|
||||
metadataBuilder.applyBasicType( TextAsMaterializedClobType.INSTANCE );
|
||||
}
|
||||
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
|
||||
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "immutable/ContractVariation.hbm.xml" };
|
||||
protected void applySettings(StandardServiceRegistryBuilder builer) {
|
||||
builer.applySetting( Environment.GENERATE_STATISTICS, "true" );
|
||||
builer.applySetting( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOrmXmlFiles() {
|
||||
return new String[] { "org/hibernate/orm/test/immutable/ContractVariation.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -91,16 +99,16 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
s.beginTransaction();
|
||||
try {
|
||||
Contract c = s.load(Contract.class, contract.getId());
|
||||
Contract c = s.load( Contract.class, contract.getId() );
|
||||
// Contract c = (Contract) s.createCriteria(Contract.class).uniqueResult();
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
|
||||
|
@ -155,13 +163,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = s.load( Contract.class, contract.getId() );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
|
||||
|
@ -221,13 +229,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
s.delete( c );
|
||||
|
@ -268,13 +276,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
s.delete( c );
|
||||
|
@ -314,13 +322,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
s.delete( c );
|
||||
|
@ -360,13 +368,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
s.delete( c );
|
||||
|
@ -407,13 +415,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
// refresh detached
|
||||
s.refresh( contract );
|
||||
assertTrue( s.isReadOnly( contract ) );
|
||||
assertEquals( contract.getCustomerName(), "gavin" );
|
||||
assertEquals( contract.getVariations().size(), 2 );
|
||||
Iterator it = contract.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", contract.getCustomerName() );
|
||||
assertEquals( 2, contract.getVariations().size() );
|
||||
Iterator<ContractVariation> it = contract.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
}
|
||||
|
@ -429,13 +437,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
s.refresh( contract );
|
||||
assertTrue( s.isReadOnly( contract ) );
|
||||
assertEquals( contract.getCustomerName(), "gavin" );
|
||||
assertEquals( contract.getVariations().size(), 2 );
|
||||
Iterator it = contract.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", contract.getCustomerName() );
|
||||
assertEquals( 2, contract.getVariations().size() );
|
||||
Iterator<ContractVariation> it = contract.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
}
|
||||
|
@ -488,7 +496,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
c.setCustomerName( "foo bar" );
|
||||
ContractVariation cv1 = (ContractVariation) c.getVariations().iterator().next();
|
||||
ContractVariation cv1 = c.getVariations().iterator().next();
|
||||
cv1.setText( "blah blah" );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertFalse( s.contains( contractVariation2 ) );
|
||||
|
@ -515,13 +523,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
s.delete( c );
|
||||
|
@ -565,7 +573,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
c.setCustomerName( "foo bar" );
|
||||
ContractVariation cv1 = (ContractVariation) c.getVariations().iterator().next();
|
||||
ContractVariation cv1 = c.getVariations().iterator().next();
|
||||
cv1.setText( "blah blah" );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertFalse( s.contains( contractVariation2 ) );
|
||||
|
@ -591,13 +599,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
s.delete( c );
|
||||
|
@ -631,13 +639,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
c.setCustomerName( "Sherman" );
|
||||
|
@ -671,13 +679,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
Contract c = s.get( Contract.class, contract.getId() );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
c.setCustomerName( "Sherman" );
|
||||
|
@ -771,13 +779,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
contract.setCustomerName( "foo bar" );
|
||||
s.update( contract );
|
||||
assertTrue( s.isReadOnly( contract ) );
|
||||
for ( Iterator it = contract.getVariations().iterator(); it.hasNext(); ) {
|
||||
for ( Iterator<ContractVariation> it = contract.getVariations().iterator(); it.hasNext(); ) {
|
||||
assertTrue( s.contains( it.next() ) );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
assertTrue( s.isReadOnly( contract ) );
|
||||
for ( Iterator it = contract.getVariations().iterator(); it.hasNext(); ) {
|
||||
ContractVariation cv = (ContractVariation) it.next();
|
||||
for ( Iterator<ContractVariation> it = contract.getVariations().iterator(); it.hasNext(); ) {
|
||||
ContractVariation cv = it.next();
|
||||
assertTrue( s.contains( cv ) );
|
||||
assertTrue( s.isReadOnly( cv ) );
|
||||
}
|
||||
|
@ -796,13 +804,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
||||
|
@ -833,7 +841,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
s -> {
|
||||
try {
|
||||
s.beginTransaction();
|
||||
ContractVariation cv1 = (ContractVariation) contract.getVariations().iterator().next();
|
||||
ContractVariation cv1 = contract.getVariations().iterator().next();
|
||||
cv1.setText( "blah blah" );
|
||||
s.update( contract );
|
||||
assertTrue( s.isReadOnly( contract ) );
|
||||
|
@ -858,13 +866,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
||||
|
@ -916,13 +924,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
@ -955,9 +963,9 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
Contract c = (Contract) s.merge( contract );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertTrue( Hibernate.isInitialized( c.getVariations() ) );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
ContractVariation cv2 = it.next();
|
||||
assertTrue( s.isReadOnly( cv1 ) );
|
||||
assertTrue( s.isReadOnly( cv2 ) );
|
||||
}
|
||||
|
@ -969,13 +977,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
}
|
||||
|
@ -1007,9 +1015,9 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
Contract c = (Contract) s.merge( contract );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertTrue( Hibernate.isInitialized( c.getVariations() ) );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
ContractVariation cv2 = it.next();
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
}
|
||||
|
@ -1020,13 +1028,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
||||
|
@ -1055,14 +1063,14 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
inTransaction(
|
||||
s -> {
|
||||
ContractVariation cv1 = (ContractVariation) contract.getVariations().iterator().next();
|
||||
ContractVariation cv1 = contract.getVariations().iterator().next();
|
||||
cv1.setText( "blah blah" );
|
||||
Contract c = (Contract) s.merge( contract );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertTrue( Hibernate.isInitialized( c.getVariations() ) );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
cv1 = (ContractVariation) it.next();
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
cv1 = it.next();
|
||||
ContractVariation cv2 = it.next();
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
assertTrue( s.isReadOnly( c ) );
|
||||
}
|
||||
|
@ -1073,13 +1081,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
}
|
||||
|
@ -1122,17 +1130,16 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
|
||||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
||||
|
@ -1172,15 +1179,15 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
assertEquals( 1, cv1.getInfos().size() );
|
||||
assertEquals( "cv1 info", ( (Info) cv1.getInfos().iterator().next() ).getText() );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
}
|
||||
|
@ -1218,16 +1225,16 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
inTransaction(
|
||||
s -> {
|
||||
Contract c = s.load( Contract.class, contract.getId() );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
Contract c = getContract( s );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
assertEquals( 1, cv1.getInfos().size() );
|
||||
assertEquals( "cv1 info", ( (Info) cv1.getInfos().iterator().next() ).getText() );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
||||
|
@ -1272,15 +1279,15 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
assertEquals( 1, cv1.getInfos().size() );
|
||||
assertEquals( "new cv1 info", ( (Info) cv1.getInfos().iterator().next() ).getText() );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
@ -1324,15 +1331,15 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
assertEquals( 1, cv1.getInfos().size() );
|
||||
assertEquals( "new cv1 info", ( (Info) cv1.getInfos().iterator().next() ).getText() );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
}
|
||||
|
@ -1385,13 +1392,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
//assertEquals( 2, c.getParties().size() );
|
||||
s.delete( c );
|
||||
|
||||
|
@ -1432,13 +1439,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
//assertEquals( 0, c.getParties().size() );
|
||||
s.delete( c );
|
||||
|
||||
|
@ -1459,8 +1466,8 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
contractVariation1.setText( "expensive" );
|
||||
ContractVariation contractVariation2 = new ContractVariation( 2, contract );
|
||||
contractVariation2.setText( "more expensive" );
|
||||
Party party = new Party( "party1" );
|
||||
contract.addParty( party );
|
||||
Party p = new Party( "party1" );
|
||||
contract.addParty( p );
|
||||
|
||||
inTransaction( s -> s.persist( contract ) );
|
||||
|
||||
|
@ -1469,21 +1476,24 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
assertUpdateCount( 0 );
|
||||
clearCounts();
|
||||
|
||||
party = (Party) contract.getParties().iterator().next();
|
||||
Party party = (Party) contract.getParties().iterator().next();
|
||||
|
||||
try (Session s = openSession()) {
|
||||
try {
|
||||
s.beginTransaction();
|
||||
s.delete( party );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( s.getTransaction().isActive() ) {
|
||||
s.getTransaction().rollback();
|
||||
inSession(
|
||||
s -> {
|
||||
try {
|
||||
s.beginTransaction();
|
||||
s.delete( party );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( s.getTransaction().isActive() ) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
assertUpdateCount( 0 );
|
||||
assertDeleteCount( 1 );
|
||||
|
@ -1492,13 +1502,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertEquals( 0, c.getParties().size() );
|
||||
s.delete( c );
|
||||
assertAllContractAndVariationsAreDeleted( s );
|
||||
|
@ -1530,7 +1540,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
Party p = (Party) contract.getParties().iterator().next();
|
||||
party.setContract( null );
|
||||
|
||||
try (Session s = openSession()) {
|
||||
inSession( s -> {
|
||||
try {
|
||||
s.beginTransaction();
|
||||
s.update( p );
|
||||
|
@ -1542,7 +1552,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
inTransaction(
|
||||
s -> {
|
||||
|
@ -1557,13 +1567,13 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
inTransaction(
|
||||
s -> {
|
||||
Contract c = getContract( s );
|
||||
assertEquals( c.getCustomerName(), "gavin" );
|
||||
assertEquals( c.getVariations().size(), 2 );
|
||||
Iterator it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = (ContractVariation) it.next();
|
||||
assertEquals( cv1.getText(), "expensive" );
|
||||
ContractVariation cv2 = (ContractVariation) it.next();
|
||||
assertEquals( cv2.getText(), "more expensive" );
|
||||
assertEquals( "gavin", c.getCustomerName() );
|
||||
assertEquals( 2, c.getVariations().size() );
|
||||
Iterator<ContractVariation> it = c.getVariations().iterator();
|
||||
ContractVariation cv1 = it.next();
|
||||
assertEquals( "expensive", cv1.getText() );
|
||||
ContractVariation cv2 = it.next();
|
||||
assertEquals( "more expensive", cv2.getText() );
|
||||
assertEquals( 1, c.getParties().size() );
|
||||
Party p1 = (Party) c.getParties().iterator().next();
|
||||
assertEquals( "party1", p1.getName() );
|
||||
|
@ -1584,17 +1594,17 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
protected void assertInsertCount(int expected) {
|
||||
int inserts = (int) sessionFactory().getStatistics().getEntityInsertCount();
|
||||
assertEquals( "unexpected insert count", expected, inserts );
|
||||
assertEquals( expected, inserts, "unexpected insert count" );
|
||||
}
|
||||
|
||||
protected void assertUpdateCount(int expected) {
|
||||
int updates = (int) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||
assertEquals( "unexpected update counts", expected, updates );
|
||||
assertEquals( expected, updates, "unexpected update counts" );
|
||||
}
|
||||
|
||||
protected void assertDeleteCount(int expected) {
|
||||
int deletes = (int) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||
assertEquals( "unexpected delete counts", expected, deletes );
|
||||
assertEquals( expected, deletes, "unexpected delete counts" );
|
||||
}
|
||||
|
||||
private Long getContractRowCount(SessionImplementor s) {
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Contract.java 7222 2005-06-19 17:22:01Z oneovthafew $
|
||||
package org.hibernate.test.immutable;
|
||||
package org.hibernate.orm.test.immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Info implements Serializable {
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Contract.java 7222 2005-06-19 17:22:01Z oneovthafew $
|
||||
package org.hibernate.test.immutable;
|
||||
package org.hibernate.orm.test.immutable;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
//$Id: ContractVariation.java 7222 2005-06-19 17:22:01Z oneovthafew $
|
||||
package org.hibernate.test.immutable;
|
||||
package org.hibernate.orm.test.immutable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
|
@ -6,9 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.testing.orm.junit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
|
@ -35,6 +38,8 @@ public abstract class BaseSessionFactoryFunctionalTest
|
|||
SessionFactoryProducer, SessionFactoryScopeAware {
|
||||
|
||||
protected static final Class[] NO_CLASSES = new Class[0];
|
||||
protected static final String[] NO_MAPPINGS = new String[0];
|
||||
|
||||
private static final Logger log = Logger.getLogger( BaseSessionFactoryFunctionalTest.class );
|
||||
|
||||
private ServiceRegistryScope registryScope;
|
||||
|
@ -75,20 +80,42 @@ public abstract class BaseSessionFactoryFunctionalTest
|
|||
@Override
|
||||
public MetadataImplementor produceModel(StandardServiceRegistry serviceRegistry) {
|
||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
|
||||
applyMetadataBuilder(metadataBuilder);
|
||||
applyMetadataSources( metadataSources );
|
||||
return (MetadataImplementor) metadataSources.buildMetadata();
|
||||
}
|
||||
|
||||
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
|
||||
}
|
||||
|
||||
protected void applyMetadataSources(MetadataSources metadataSources) {
|
||||
|
||||
for ( Class annotatedClass : getAnnotatedClasses() ) {
|
||||
metadataSources.addAnnotatedClass( annotatedClass );
|
||||
}
|
||||
String[] xmlFiles = getOrmXmlFiles();
|
||||
if ( xmlFiles != null ) {
|
||||
for ( String xmlFile : xmlFiles ) {
|
||||
try ( InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ) ) {
|
||||
metadataSources.addInputStream( is );
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return NO_CLASSES;
|
||||
}
|
||||
|
||||
protected String[] getOrmXmlFiles() {
|
||||
return NO_MAPPINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectTestModelScope(DomainModelScope modelScope) {
|
||||
this.modelScope = modelScope;
|
||||
|
@ -163,4 +190,12 @@ public abstract class BaseSessionFactoryFunctionalTest
|
|||
return sessionFactoryScope().fromTransaction( action );
|
||||
}
|
||||
|
||||
protected void inSession(Consumer<SessionImplementor> action){
|
||||
sessionFactoryScope.inSession( action );
|
||||
}
|
||||
|
||||
protected <T> T fromSession(Function<SessionImplementor, T> action){
|
||||
return sessionFactoryScope.fromSession( action );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue