mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-18 00:55:16 +00:00
HHH-13720: Implement mapping model support for plural attributes - sorted set;
HHH-13715: HQL/Criteria DELETE support - support for cleaning-up collection tables
This commit is contained in:
parent
7b489b180c
commit
75d436ab25
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* 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.metamodel.mapping;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||||
|
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||||
|
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||||
|
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||||
|
|
||||||
|
import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class MappingModelHelper {
|
||||||
|
public static Expression buildColumnReferenceExpression(
|
||||||
|
ModelPart modelPart,
|
||||||
|
SqlExpressionResolver sqlExpressionResolver,
|
||||||
|
SessionFactoryImplementor sessionFactory) {
|
||||||
|
final int jdbcTypeCount = modelPart.getJdbcTypeCount( sessionFactory.getTypeConfiguration() );
|
||||||
|
|
||||||
|
if ( jdbcTypeCount == 1 ) {
|
||||||
|
assert modelPart instanceof BasicValuedModelPart;
|
||||||
|
final BasicValuedModelPart basicPart = (BasicValuedModelPart) modelPart;
|
||||||
|
if ( sqlExpressionResolver == null ) {
|
||||||
|
return new ColumnReference(
|
||||||
|
basicPart.getContainingTableExpression(),
|
||||||
|
basicPart.getMappedColumnExpression(),
|
||||||
|
basicPart.getJdbcMapping(),
|
||||||
|
sessionFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return sqlExpressionResolver.resolveSqlExpression(
|
||||||
|
createColumnReferenceKey( basicPart.getContainingTableExpression(), basicPart.getMappedColumnExpression() ),
|
||||||
|
sqlAstProcessingState -> new ColumnReference(
|
||||||
|
basicPart.getContainingTableExpression(),
|
||||||
|
basicPart.getMappedColumnExpression(),
|
||||||
|
basicPart.getJdbcMapping(),
|
||||||
|
sessionFactory
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final List<ColumnReference> columnReferences = new ArrayList<>( jdbcTypeCount );
|
||||||
|
modelPart.visitColumns(
|
||||||
|
(containingTableExpression, columnExpression, jdbcMapping) -> {
|
||||||
|
final ColumnReference colRef;
|
||||||
|
if ( sqlExpressionResolver == null ) {
|
||||||
|
colRef = new ColumnReference(
|
||||||
|
containingTableExpression,
|
||||||
|
columnExpression,
|
||||||
|
jdbcMapping,
|
||||||
|
sessionFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
colRef = (ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
||||||
|
createColumnReferenceKey( containingTableExpression, columnExpression ),
|
||||||
|
sqlAstProcessingState -> new ColumnReference(
|
||||||
|
containingTableExpression,
|
||||||
|
columnExpression,
|
||||||
|
jdbcMapping,
|
||||||
|
sessionFactory
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
columnReferences.add( colRef );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return new SqlTuple( columnReferences, modelPart );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MappingModelHelper() {
|
||||||
|
// disallow direct instantiation
|
||||||
|
}
|
||||||
|
}
|
@ -6,9 +6,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.query.hql.internal;
|
package org.hibernate.query.hql.internal;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.query.SemanticException;
|
import org.hibernate.query.SemanticException;
|
||||||
|
import org.hibernate.query.hql.HqlInterpretationException;
|
||||||
import org.hibernate.query.hql.spi.DotIdentifierConsumer;
|
import org.hibernate.query.hql.spi.DotIdentifierConsumer;
|
||||||
import org.hibernate.query.hql.spi.SemanticPathPart;
|
import org.hibernate.query.hql.spi.SemanticPathPart;
|
||||||
import org.hibernate.query.hql.spi.SqmPathRegistry;
|
import org.hibernate.query.hql.spi.SqmPathRegistry;
|
||||||
@ -139,6 +142,16 @@ private static SqmFrom createJoin(
|
|||||||
boolean isTerminal,
|
boolean isTerminal,
|
||||||
SqmCreationState creationState) {
|
SqmCreationState creationState) {
|
||||||
final SqmPathSource subPathSource = lhs.getReferencedPathSource().findSubPathSource( name );
|
final SqmPathSource subPathSource = lhs.getReferencedPathSource().findSubPathSource( name );
|
||||||
|
if ( subPathSource == null ) {
|
||||||
|
throw new HqlInterpretationException(
|
||||||
|
String.format(
|
||||||
|
Locale.ROOT,
|
||||||
|
"Could not locate specified joinable path : %s -> %s",
|
||||||
|
lhs.getNavigablePath(),
|
||||||
|
name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
final SqmAttributeJoin join = ( (SqmJoinable) subPathSource ).createSqmJoin(
|
final SqmAttributeJoin join = ( (SqmJoinable) subPathSource ).createSqmJoin(
|
||||||
lhs,
|
lhs,
|
||||||
joinType,
|
joinType,
|
||||||
|
@ -542,7 +542,7 @@ private NonSelectQueryPlan buildDeleteQueryPlan() {
|
|||||||
|
|
||||||
final SqmMultiTableMutationStrategy multiTableStrategy = entityDescriptor.getSqmMultiTableMutationStrategy();
|
final SqmMultiTableMutationStrategy multiTableStrategy = entityDescriptor.getSqmMultiTableMutationStrategy();
|
||||||
if ( multiTableStrategy == null ) {
|
if ( multiTableStrategy == null ) {
|
||||||
return new SimpleDeleteQueryPlan( sqmDelete, domainParameterXref );
|
return new SimpleDeleteQueryPlan( entityDescriptor, sqmDelete, domainParameterXref );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new MultiTableDeleteQueryPlan( sqmDelete, domainParameterXref, multiTableStrategy );
|
return new MultiTableDeleteQueryPlan( sqmDelete, domainParameterXref, multiTableStrategy );
|
||||||
|
@ -12,9 +12,14 @@
|
|||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
|
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||||
|
import org.hibernate.metamodel.mapping.MappingModelHelper;
|
||||||
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.query.spi.NonSelectQueryPlan;
|
import org.hibernate.query.spi.NonSelectQueryPlan;
|
||||||
import org.hibernate.query.spi.QueryEngine;
|
import org.hibernate.query.spi.QueryEngine;
|
||||||
import org.hibernate.query.spi.QueryParameterImplementor;
|
import org.hibernate.query.spi.QueryParameterImplementor;
|
||||||
|
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||||
import org.hibernate.query.sqm.sql.SimpleSqmDeleteTranslation;
|
import org.hibernate.query.sqm.sql.SimpleSqmDeleteTranslation;
|
||||||
import org.hibernate.query.sqm.sql.SimpleSqmDeleteTranslator;
|
import org.hibernate.query.sqm.sql.SimpleSqmDeleteTranslator;
|
||||||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||||
@ -22,26 +27,36 @@
|
|||||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||||
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
|
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
|
||||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||||
|
import org.hibernate.sql.ast.tree.from.MutatingTableReferenceGroupWrapper;
|
||||||
|
import org.hibernate.sql.ast.tree.from.StandardTableGroup;
|
||||||
|
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
|
||||||
|
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||||
import org.hibernate.sql.exec.spi.JdbcDelete;
|
import org.hibernate.sql.exec.spi.JdbcDelete;
|
||||||
import org.hibernate.sql.exec.spi.JdbcParameter;
|
import org.hibernate.sql.exec.spi.JdbcParameter;
|
||||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||||
|
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
|
public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
|
||||||
|
private final EntityMappingType entityDescriptor;
|
||||||
private final SqmDeleteStatement sqmDelete;
|
private final SqmDeleteStatement sqmDelete;
|
||||||
private final DomainParameterXref domainParameterXref;
|
private final DomainParameterXref domainParameterXref;
|
||||||
|
|
||||||
private JdbcDelete jdbcDelete;
|
private JdbcDelete jdbcDelete;
|
||||||
private FromClauseAccess tableGroupAccess;
|
private SimpleSqmDeleteTranslation sqmInterpretation;
|
||||||
private Map<QueryParameterImplementor<?>, Map<SqmParameter, List<JdbcParameter>>> jdbcParamsXref;
|
private Map<QueryParameterImplementor<?>, Map<SqmParameter, List<JdbcParameter>>> jdbcParamsXref;
|
||||||
|
|
||||||
public SimpleDeleteQueryPlan(
|
public SimpleDeleteQueryPlan(
|
||||||
|
EntityMappingType entityDescriptor,
|
||||||
SqmDeleteStatement sqmDelete,
|
SqmDeleteStatement sqmDelete,
|
||||||
DomainParameterXref domainParameterXref) {
|
DomainParameterXref domainParameterXref) {
|
||||||
|
assert entityDescriptor.getEntityName().equals( sqmDelete.getTarget().getEntityName() );
|
||||||
|
|
||||||
|
this.entityDescriptor = entityDescriptor;
|
||||||
this.sqmDelete = sqmDelete;
|
this.sqmDelete = sqmDelete;
|
||||||
this.domainParameterXref = domainParameterXref;
|
this.domainParameterXref = domainParameterXref;
|
||||||
}
|
}
|
||||||
@ -63,9 +78,7 @@ public int executeUpdate(ExecutionContext executionContext) {
|
|||||||
factory
|
factory
|
||||||
);
|
);
|
||||||
|
|
||||||
final SimpleSqmDeleteTranslation sqmInterpretation = translator.translate( sqmDelete );
|
sqmInterpretation = translator.translate( sqmDelete );
|
||||||
|
|
||||||
tableGroupAccess = translator.getFromClauseAccess();
|
|
||||||
|
|
||||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
||||||
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
|
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
|
||||||
@ -78,7 +91,6 @@ public int executeUpdate(ExecutionContext executionContext) {
|
|||||||
domainParameterXref,
|
domainParameterXref,
|
||||||
sqmInterpretation::getJdbcParamsBySqmParam
|
sqmInterpretation::getJdbcParamsBySqmParam
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||||
@ -86,10 +98,57 @@ public int executeUpdate(ExecutionContext executionContext) {
|
|||||||
domainParameterXref,
|
domainParameterXref,
|
||||||
jdbcParamsXref,
|
jdbcParamsXref,
|
||||||
factory.getDomainModel(),
|
factory.getDomainModel(),
|
||||||
tableGroupAccess::findTableGroup,
|
sqmInterpretation.getFromClauseAccess()::findTableGroup,
|
||||||
executionContext.getSession()
|
executionContext.getSession()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final boolean missingRestriction = sqmDelete.getWhereClause() == null
|
||||||
|
|| sqmDelete.getWhereClause().getPredicate() == null;
|
||||||
|
if ( missingRestriction ) {
|
||||||
|
assert domainParameterXref.getSqmParameterCount() == 0;
|
||||||
|
assert jdbcParamsXref.isEmpty();
|
||||||
|
assert jdbcParameterBindings.getBindings().size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SqmMutationStrategyHelper.cleanUpCollectionTables(
|
||||||
|
entityDescriptor,
|
||||||
|
(tableReference, attributeMapping) -> {
|
||||||
|
if ( missingRestriction ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ForeignKeyDescriptor fkDescriptor = attributeMapping.getKeyDescriptor();
|
||||||
|
final Expression fkColumnExpression = MappingModelHelper.buildColumnReferenceExpression(
|
||||||
|
fkDescriptor,
|
||||||
|
null,
|
||||||
|
factory
|
||||||
|
);
|
||||||
|
|
||||||
|
final QuerySpec matchingIdSubQuery = new QuerySpec( false );
|
||||||
|
|
||||||
|
final Expression fkTargetColumnExpression = MappingModelHelper.buildColumnReferenceExpression(
|
||||||
|
fkDescriptor,
|
||||||
|
sqmInterpretation.getSqlExpressionResolver(),
|
||||||
|
factory
|
||||||
|
);
|
||||||
|
matchingIdSubQuery.getSelectClause().addSqlSelection( new SqlSelectionImpl( 1, 0, fkTargetColumnExpression, null ) );
|
||||||
|
|
||||||
|
matchingIdSubQuery.getFromClause().addRoot(
|
||||||
|
new MutatingTableReferenceGroupWrapper(
|
||||||
|
new NavigablePath( attributeMapping.getRootPathName() ),
|
||||||
|
attributeMapping,
|
||||||
|
sqmInterpretation.getSqlAst().getTargetTable()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
matchingIdSubQuery.applyPredicate( sqmInterpretation.getSqlAst().getRestriction() );
|
||||||
|
|
||||||
|
return new InSubQueryPredicate( fkColumnExpression, matchingIdSubQuery, false );
|
||||||
|
},
|
||||||
|
missingRestriction ? JdbcParameterBindings.NO_BINDINGS : jdbcParameterBindings,
|
||||||
|
executionContext
|
||||||
|
);
|
||||||
|
|
||||||
return jdbcServices.getJdbcMutationExecutor().execute(
|
return jdbcServices.getJdbcMutationExecutor().execute(
|
||||||
jdbcDelete,
|
jdbcDelete,
|
||||||
jdbcParameterBindings,
|
jdbcParameterBindings,
|
||||||
|
@ -6,14 +6,30 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.query.sqm.mutation.internal;
|
package org.hibernate.query.sqm.mutation.internal;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
import org.hibernate.NotYetImplementedFor6Exception;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.mapping.RootClass;
|
import org.hibernate.mapping.RootClass;
|
||||||
|
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
|
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||||
|
import org.hibernate.metamodel.mapping.ModelPart;
|
||||||
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
|
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
|
||||||
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
|
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
|
||||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||||
|
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||||
|
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
|
||||||
|
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||||
|
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||||
|
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||||
|
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||||
|
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
@ -52,4 +68,70 @@ public static SqmMultiTableMutationStrategy resolveStrategy(
|
|||||||
.getFallbackSqmMutationStrategy( rootEntityDescriptor, creationContext );
|
.getFallbackSqmMutationStrategy( rootEntityDescriptor, creationContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void cleanUpCollectionTables(
|
||||||
|
EntityMappingType entityDescriptor,
|
||||||
|
BiFunction<TableReference, PluralAttributeMapping, Predicate> restrictionProducer,
|
||||||
|
JdbcParameterBindings jdbcParameterBindings,
|
||||||
|
ExecutionContext executionContext) {
|
||||||
|
if ( ! entityDescriptor.getEntityPersister().hasCollections() ) {
|
||||||
|
// none to clean-up
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entityDescriptor.visitAttributeMappings(
|
||||||
|
attributeMapping -> {
|
||||||
|
if ( attributeMapping instanceof PluralAttributeMapping ) {
|
||||||
|
cleanUpCollectionTable(
|
||||||
|
(PluralAttributeMapping) attributeMapping,
|
||||||
|
entityDescriptor,
|
||||||
|
restrictionProducer,
|
||||||
|
jdbcParameterBindings,
|
||||||
|
executionContext
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void cleanUpCollectionTable(
|
||||||
|
PluralAttributeMapping attributeMapping,
|
||||||
|
EntityMappingType entityDescriptor,
|
||||||
|
BiFunction<TableReference, PluralAttributeMapping, Predicate> restrictionProducer,
|
||||||
|
JdbcParameterBindings jdbcParameterBindings,
|
||||||
|
ExecutionContext executionContext) {
|
||||||
|
final String separateCollectionTable = attributeMapping.getSeparateCollectionTable();
|
||||||
|
|
||||||
|
final SessionFactoryImplementor sessionFactory = executionContext.getSession().getFactory();
|
||||||
|
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||||
|
|
||||||
|
if ( separateCollectionTable == null ) {
|
||||||
|
// one-to-many - update the matching rows in the associated table setting the fk column(s) to null
|
||||||
|
// not yet implemented - do nothing
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// element-collection or many-to-many - delete the collection-table row
|
||||||
|
|
||||||
|
final TableReference tableReference = new TableReference( separateCollectionTable, null, true, sessionFactory );
|
||||||
|
|
||||||
|
final DeleteStatement sqlAstDelete = new DeleteStatement(
|
||||||
|
tableReference,
|
||||||
|
restrictionProducer.apply( tableReference, attributeMapping )
|
||||||
|
);
|
||||||
|
|
||||||
|
final SqlAstDeleteTranslator sqlAstDeleteTranslator = jdbcServices.getJdbcEnvironment()
|
||||||
|
.getSqlAstTranslatorFactory()
|
||||||
|
.buildDeleteTranslator( sessionFactory );
|
||||||
|
|
||||||
|
jdbcServices.getJdbcMutationExecutor().execute(
|
||||||
|
sqlAstDeleteTranslator.translate( sqlAstDelete ),
|
||||||
|
jdbcParameterBindings,
|
||||||
|
sql -> executionContext.getSession()
|
||||||
|
.getJdbcCoordinator()
|
||||||
|
.getStatementPreparer()
|
||||||
|
.prepareStatement( sql ),
|
||||||
|
(integer, preparedStatement) -> {},
|
||||||
|
executionContext
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,17 @@
|
|||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.metamodel.mapping.ColumnConsumer;
|
import org.hibernate.metamodel.mapping.ColumnConsumer;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
|
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||||
|
import org.hibernate.metamodel.mapping.MappingModelHelper;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.persister.entity.Joinable;
|
import org.hibernate.persister.entity.Joinable;
|
||||||
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.query.spi.QueryOptions;
|
import org.hibernate.query.spi.QueryOptions;
|
||||||
import org.hibernate.query.spi.QueryParameterBindings;
|
import org.hibernate.query.spi.QueryParameterBindings;
|
||||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||||
import org.hibernate.query.sqm.internal.SqmUtil;
|
import org.hibernate.query.sqm.internal.SqmUtil;
|
||||||
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
|
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
|
||||||
|
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||||
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||||
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
|
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
|
||||||
@ -38,6 +42,7 @@
|
|||||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||||
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||||
|
import org.hibernate.sql.ast.tree.from.MutatingTableReferenceGroupWrapper;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||||
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
|
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
|
||||||
@ -47,6 +52,7 @@
|
|||||||
import org.hibernate.sql.exec.spi.JdbcDelete;
|
import org.hibernate.sql.exec.spi.JdbcDelete;
|
||||||
import org.hibernate.sql.exec.spi.JdbcParameter;
|
import org.hibernate.sql.exec.spi.JdbcParameter;
|
||||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||||
|
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
@ -392,6 +398,26 @@ private int executeUsingIdTable(
|
|||||||
executionContext
|
executionContext
|
||||||
);
|
);
|
||||||
|
|
||||||
|
SqmMutationStrategyHelper.cleanUpCollectionTables(
|
||||||
|
entityDescriptor,
|
||||||
|
(tableReference, attributeMapping) -> {
|
||||||
|
final ForeignKeyDescriptor fkDescriptor = attributeMapping.getKeyDescriptor();
|
||||||
|
|
||||||
|
return new InSubQueryPredicate(
|
||||||
|
MappingModelHelper.buildColumnReferenceExpression(
|
||||||
|
fkDescriptor,
|
||||||
|
null,
|
||||||
|
sessionFactory
|
||||||
|
),
|
||||||
|
idTableSubQuery,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
},
|
||||||
|
JdbcParameterBindings.NO_BINDINGS,
|
||||||
|
executionContext
|
||||||
|
);
|
||||||
|
|
||||||
entityDescriptor.visitConstraintOrderedTables(
|
entityDescriptor.visitConstraintOrderedTables(
|
||||||
(tableExpression, tableKeyColumnVisitationSupplier) -> deleteFromTableUsingIdTable(
|
(tableExpression, tableKeyColumnVisitationSupplier) -> deleteFromTableUsingIdTable(
|
||||||
tableExpression,
|
tableExpression,
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
|
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||||
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
|
import org.hibernate.sql.ast.SqlAstDeleteTranslator;
|
||||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||||
@ -37,6 +38,13 @@ public int execute(ExecutionContext executionContext) {
|
|||||||
// will visit
|
// will visit
|
||||||
final AtomicInteger result = new AtomicInteger();
|
final AtomicInteger result = new AtomicInteger();
|
||||||
|
|
||||||
|
SqmMutationStrategyHelper.cleanUpCollectionTables(
|
||||||
|
entityDescriptor,
|
||||||
|
(tableReference, attributeMapping) -> null,
|
||||||
|
JdbcParameterBindings.NO_BINDINGS,
|
||||||
|
executionContext
|
||||||
|
);
|
||||||
|
|
||||||
entityDescriptor.visitConstraintOrderedTables(
|
entityDescriptor.visitConstraintOrderedTables(
|
||||||
(tableExpression, tableKeyColumnsVisitationSupplier) -> {
|
(tableExpression, tableKeyColumnsVisitationSupplier) -> {
|
||||||
final int rows = deleteFrom( tableExpression, executionContext );
|
final int rows = deleteFrom( tableExpression, executionContext );
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||||
|
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||||
|
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||||
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
|
||||||
import org.hibernate.sql.exec.spi.JdbcParameter;
|
import org.hibernate.sql.exec.spi.JdbcParameter;
|
||||||
|
|
||||||
@ -19,12 +21,18 @@
|
|||||||
public class SimpleSqmDeleteTranslation implements SqmTranslation {
|
public class SimpleSqmDeleteTranslation implements SqmTranslation {
|
||||||
private final DeleteStatement sqlAst;
|
private final DeleteStatement sqlAst;
|
||||||
private final Map<SqmParameter, List<JdbcParameter>> jdbcParamMap;
|
private final Map<SqmParameter, List<JdbcParameter>> jdbcParamMap;
|
||||||
|
private final SqlExpressionResolver sqlExpressionResolver;
|
||||||
|
private final FromClauseAccess fromClauseAccess;
|
||||||
|
|
||||||
public SimpleSqmDeleteTranslation(
|
public SimpleSqmDeleteTranslation(
|
||||||
DeleteStatement sqlAst,
|
DeleteStatement sqlAst,
|
||||||
Map<SqmParameter, List<JdbcParameter>> jdbcParamMap) {
|
Map<SqmParameter, List<JdbcParameter>> jdbcParamMap,
|
||||||
|
SqlExpressionResolver sqlExpressionResolver,
|
||||||
|
FromClauseAccess fromClauseAccess) {
|
||||||
this.sqlAst = sqlAst;
|
this.sqlAst = sqlAst;
|
||||||
this.jdbcParamMap = jdbcParamMap;
|
this.jdbcParamMap = jdbcParamMap;
|
||||||
|
this.sqlExpressionResolver = sqlExpressionResolver;
|
||||||
|
this.fromClauseAccess = fromClauseAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,4 +44,12 @@ public DeleteStatement getSqlAst() {
|
|||||||
public Map<SqmParameter, List<JdbcParameter>> getJdbcParamsBySqmParam() {
|
public Map<SqmParameter, List<JdbcParameter>> getJdbcParamsBySqmParam() {
|
||||||
return jdbcParamMap;
|
return jdbcParamMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SqlExpressionResolver getSqlExpressionResolver() {
|
||||||
|
return sqlExpressionResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FromClauseAccess getFromClauseAccess() {
|
||||||
|
return fromClauseAccess;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,10 +53,21 @@ public StandardSqmDeleteTranslator(
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SimpleSqmDeleteTranslation translate(SqmDeleteStatement statement) {
|
public SimpleSqmDeleteTranslation translate(SqmDeleteStatement statement) {
|
||||||
|
SqlAstProcessingStateImpl processingState = new SqlAstProcessingStateImpl(
|
||||||
|
null,
|
||||||
|
this,
|
||||||
|
getCurrentClauseStack()::getCurrent
|
||||||
|
);
|
||||||
|
|
||||||
|
getProcessingStateStack().push( processingState );
|
||||||
|
|
||||||
final DeleteStatement deleteStatement = visitDeleteStatement( statement );
|
final DeleteStatement deleteStatement = visitDeleteStatement( statement );
|
||||||
|
|
||||||
return new SimpleSqmDeleteTranslation(
|
return new SimpleSqmDeleteTranslation(
|
||||||
deleteStatement,
|
deleteStatement,
|
||||||
getJdbcParamsBySqmParam()
|
getJdbcParamsBySqmParam(),
|
||||||
|
processingState.getSqlExpressionResolver(),
|
||||||
|
getFromClauseAccess()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,14 +77,6 @@ public DeleteStatement visitDeleteStatement(SqmDeleteStatement statement) {
|
|||||||
final EntityPersister entityDescriptor = getCreationContext().getDomainModel().getEntityDescriptor( entityName );
|
final EntityPersister entityDescriptor = getCreationContext().getDomainModel().getEntityDescriptor( entityName );
|
||||||
assert entityDescriptor != null;
|
assert entityDescriptor != null;
|
||||||
|
|
||||||
getProcessingStateStack().push(
|
|
||||||
new SqlAstProcessingStateImpl(
|
|
||||||
null,
|
|
||||||
this,
|
|
||||||
getCurrentClauseStack()::getCurrent
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final NavigablePath rootPath = new NavigablePath( entityName );
|
final NavigablePath rootPath = new NavigablePath( entityName );
|
||||||
final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup(
|
final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup(
|
||||||
|
@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* 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.sql.ast.tree.from;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.hibernate.LockMode;
|
||||||
|
import org.hibernate.metamodel.mapping.ModelPartContainer;
|
||||||
|
import org.hibernate.query.NavigablePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class MutatingTableReferenceGroupWrapper implements VirtualTableGroup {
|
||||||
|
private final NavigablePath navigablePath;
|
||||||
|
private final ModelPartContainer modelPart;
|
||||||
|
private final TableReference mutatingTableReference;
|
||||||
|
|
||||||
|
public MutatingTableReferenceGroupWrapper(
|
||||||
|
NavigablePath navigablePath,
|
||||||
|
ModelPartContainer modelPart,
|
||||||
|
TableReference mutatingTableReference) {
|
||||||
|
this.navigablePath = navigablePath;
|
||||||
|
this.modelPart = modelPart;
|
||||||
|
this.mutatingTableReference = mutatingTableReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigablePath getNavigablePath() {
|
||||||
|
return navigablePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroupAlias() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelPartContainer getModelPart() {
|
||||||
|
return modelPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableReference getPrimaryTableReference() {
|
||||||
|
return mutatingTableReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableReference resolveTableReference(String tableExpression, Supplier<TableReference> creator) {
|
||||||
|
return resolveTableReference( tableExpression );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableReference resolveTableReference(String tableExpression) {
|
||||||
|
return mutatingTableReference.getTableExpression().equals( tableExpression )
|
||||||
|
? mutatingTableReference
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyAffectedTableNames(Consumer<String> nameCollector) {
|
||||||
|
nameCollector.accept( mutatingTableReference.getTableExpression() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LockMode getLockMode() {
|
||||||
|
return LockMode.WRITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<TableGroupJoin> getTableGroupJoins() {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasTableGroupJoins() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTableGroupJoins(Set<TableGroupJoin> joins) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTableGroupJoin(TableGroupJoin join) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitTableGroupJoins(Consumer<TableGroupJoin> consumer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableReferenceJoin> getTableReferenceJoins() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInnerJoinPossible() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -6,9 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.loading.multiLoad;
|
package org.hibernate.orm.test.loading.multiLoad;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.testing.hamcrest.CollectionMatchers;
|
||||||
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||||
import org.hibernate.testing.orm.domain.gambit.BasicEntity;
|
import org.hibernate.testing.orm.domain.gambit.BasicEntity;
|
||||||
import org.hibernate.testing.orm.domain.gambit.EntityWithAggregateId;
|
import org.hibernate.testing.orm.domain.gambit.EntityWithAggregateId;
|
||||||
@ -16,17 +16,12 @@
|
|||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryFunctionalTesting;
|
import org.hibernate.testing.orm.junit.SessionFactoryFunctionalTesting;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.hamcrest.BaseMatcher;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import org.hamcrest.CoreMatchers;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import org.hamcrest.Description;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +127,7 @@ public void testBasicEntityUnOrderedDeleteCheckLoad(SessionFactoryScope scope) {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
results,
|
results,
|
||||||
HasNullElementsMatcher.hasNoNullElements()
|
CollectionMatchers.hasNoNullElements()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +142,7 @@ public void testBasicEntityUnOrderedDeleteCheckLoad(SessionFactoryScope scope) {
|
|||||||
// however, we should now have a null element for the deleted entity
|
// however, we should now have a null element for the deleted entity
|
||||||
assertThat(
|
assertThat(
|
||||||
results,
|
results,
|
||||||
HasNullElementsMatcher.hasNullElements()
|
CollectionMatchers.hasNullElements()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,52 +201,4 @@ public void dropTestData(SessionFactoryScope scope) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class HasNullElementsMatcher<C extends Collection<?>> extends BaseMatcher<C> {
|
|
||||||
public static final HasNullElementsMatcher INSTANCE = new HasNullElementsMatcher( false );
|
|
||||||
public static final HasNullElementsMatcher NEGATED_INSTANCE = new HasNullElementsMatcher( true );
|
|
||||||
|
|
||||||
public static <X extends Collection<?>> HasNullElementsMatcher<X> hasNullElements() {
|
|
||||||
//noinspection unchecked
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <X extends Collection<?>> HasNullElementsMatcher<X> hasNoNullElements() {
|
|
||||||
//noinspection unchecked
|
|
||||||
return NEGATED_INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final boolean negated;
|
|
||||||
|
|
||||||
public HasNullElementsMatcher(boolean negated) {
|
|
||||||
this.negated = negated;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(Object item) {
|
|
||||||
assertThat( item, instanceOf( Collection.class ) );
|
|
||||||
|
|
||||||
//noinspection unchecked
|
|
||||||
C collection = (C) item;
|
|
||||||
|
|
||||||
if ( negated ) {
|
|
||||||
// check no-null-elements - if any is null, this check fails
|
|
||||||
collection.forEach( e -> assertThat( e, notNullValue() ) );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean foundOne = false;
|
|
||||||
for ( Object e : collection ) {
|
|
||||||
if ( e == null ) {
|
|
||||||
foundOne = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return foundOne;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void describeTo(Description description) {
|
|
||||||
description.appendText( "had null elements" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,148 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* 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.orm.test.metamodel.mapping.collections;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Convert;
|
|
||||||
import javax.persistence.ElementCollection;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.OrderColumn;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
@Entity(name = "EntityContainingLists")
|
|
||||||
@Table(name = "entity_containing_lists")
|
|
||||||
public class EntityContainingLists {
|
|
||||||
private Integer id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private List<String> listOfBasics;
|
|
||||||
private List<EnumValue> listOfConvertedBasics;
|
|
||||||
private List<EnumValue> listOfEnums;
|
|
||||||
private List<SomeStuff> listOfComponents;
|
|
||||||
private List<SimpleEntity> listOfEntities;
|
|
||||||
|
|
||||||
public EntityContainingLists() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityContainingLists(Integer id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@OrderColumn
|
|
||||||
public List<String> getListOfBasics() {
|
|
||||||
return listOfBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setListOfBasics(List<String> listOfBasics) {
|
|
||||||
this.listOfBasics = listOfBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addBasic(String basic) {
|
|
||||||
if ( listOfBasics == null ) {
|
|
||||||
listOfBasics = new ArrayList<>();
|
|
||||||
}
|
|
||||||
listOfBasics.add( basic );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@OrderColumn
|
|
||||||
@Convert(converter = EnumValueConverter.class)
|
|
||||||
public List<EnumValue> getListOfConvertedBasics() {
|
|
||||||
return listOfConvertedBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setListOfConvertedBasics(List<EnumValue> listOfConvertedBasics) {
|
|
||||||
this.listOfConvertedBasics = listOfConvertedBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addConvertedBasic(EnumValue value) {
|
|
||||||
if ( listOfConvertedBasics == null ) {
|
|
||||||
listOfConvertedBasics = new ArrayList<>();
|
|
||||||
}
|
|
||||||
listOfConvertedBasics.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
@OrderColumn
|
|
||||||
public List<EnumValue> getListOfEnums() {
|
|
||||||
return listOfEnums;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setListOfEnums(List<EnumValue> listOfEnums) {
|
|
||||||
this.listOfEnums = listOfEnums;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEnum(EnumValue value) {
|
|
||||||
if ( listOfEnums == null ) {
|
|
||||||
listOfEnums = new ArrayList<>();
|
|
||||||
}
|
|
||||||
listOfEnums.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@OrderColumn
|
|
||||||
public List<SomeStuff> getListOfComponents() {
|
|
||||||
return listOfComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setListOfComponents(List<SomeStuff> listOfComponents) {
|
|
||||||
this.listOfComponents = listOfComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addComponent(SomeStuff value) {
|
|
||||||
if ( listOfComponents == null ) {
|
|
||||||
listOfComponents = new ArrayList<>();
|
|
||||||
}
|
|
||||||
listOfComponents.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL)
|
|
||||||
@OrderColumn
|
|
||||||
public List<SimpleEntity> getListOfEntities() {
|
|
||||||
return listOfEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setListOfEntities(List<SimpleEntity> listOfEntities) {
|
|
||||||
this.listOfEntities = listOfEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSimpleEntity(SimpleEntity value) {
|
|
||||||
if ( listOfEntities == null ) {
|
|
||||||
listOfEntities = new ArrayList<>();
|
|
||||||
}
|
|
||||||
listOfEntities.add( value );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,206 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* 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.orm.test.metamodel.mapping.collections;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.persistence.CollectionTable;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Convert;
|
|
||||||
import javax.persistence.ElementCollection;
|
|
||||||
import javax.persistence.Embedded;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
import javax.persistence.MapKeyColumn;
|
|
||||||
import javax.persistence.MapKeyEnumerated;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Entity
|
|
||||||
@Table(name = "entity_containing_maps")
|
|
||||||
public class EntityContainingMaps {
|
|
||||||
private Integer id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
|
|
||||||
private Map<String,String> basicByBasic;
|
|
||||||
private Map<EnumValue,String> basicByEnum;
|
|
||||||
private Map<EnumValue,String> basicByConvertedEnum;
|
|
||||||
|
|
||||||
private Map<String,SomeStuff> someStuffByBasic;
|
|
||||||
private Map<SomeStuff, String> basicBySomeStuff;
|
|
||||||
|
|
||||||
private Map<String,SimpleEntity> oneToManyByBasic;
|
|
||||||
private Map<SimpleEntity,String> basicByOneToMany;
|
|
||||||
|
|
||||||
private Map<String,SimpleEntity> manyToManyByBasic;
|
|
||||||
|
|
||||||
public EntityContainingMaps() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityContainingMaps(Integer id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@MapKeyColumn( name = "map_key" )
|
|
||||||
@Column( name = "map_val")
|
|
||||||
public Map<String, String> getBasicByBasic() {
|
|
||||||
return basicByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicByBasic(Map<String, String> basicByBasic) {
|
|
||||||
this.basicByBasic = basicByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addBasicByBasic(String key, String val) {
|
|
||||||
if ( basicByBasic == null ) {
|
|
||||||
basicByBasic = new HashMap<>();
|
|
||||||
}
|
|
||||||
basicByBasic.put( key, val );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@MapKeyEnumerated
|
|
||||||
public Map<EnumValue, String> getBasicByEnum() {
|
|
||||||
return basicByEnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicByEnum(Map<EnumValue, String> basicByEnum) {
|
|
||||||
this.basicByEnum = basicByEnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addBasicByEnum(EnumValue key, String val) {
|
|
||||||
if ( basicByEnum == null ) {
|
|
||||||
basicByEnum = new HashMap<>();
|
|
||||||
}
|
|
||||||
basicByEnum.put( key, val );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@Convert(attributeName = "key", converter = EnumValueConverter.class)
|
|
||||||
public Map<EnumValue, String> getBasicByConvertedEnum() {
|
|
||||||
return basicByConvertedEnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicByConvertedEnum(Map<EnumValue, String> basicByConvertedEnum) {
|
|
||||||
this.basicByConvertedEnum = basicByConvertedEnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addBasicByConvertedEnum(EnumValue key, String value) {
|
|
||||||
if ( basicByConvertedEnum == null ) {
|
|
||||||
basicByConvertedEnum = new HashMap<>();
|
|
||||||
}
|
|
||||||
basicByConvertedEnum.put( key, value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
public Map<String, SomeStuff> getSomeStuffByBasic() {
|
|
||||||
return someStuffByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSomeStuffByBasic(Map<String, SomeStuff> someStuffByBasic) {
|
|
||||||
this.someStuffByBasic = someStuffByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSomeStuffByBasic(String key, SomeStuff value) {
|
|
||||||
if ( someStuffByBasic == null ) {
|
|
||||||
someStuffByBasic = new HashMap<>();
|
|
||||||
}
|
|
||||||
someStuffByBasic.put( key, value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
public Map<SomeStuff, String> getBasicBySomeStuff() {
|
|
||||||
return basicBySomeStuff;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicBySomeStuff(Map<SomeStuff, String> basicBySomeStuff) {
|
|
||||||
this.basicBySomeStuff = basicBySomeStuff;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addBasicBySomeStuff(SomeStuff key, String val) {
|
|
||||||
if ( basicBySomeStuff == null ) {
|
|
||||||
basicBySomeStuff = new HashMap<>();
|
|
||||||
}
|
|
||||||
basicBySomeStuff.put( key, val );
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany
|
|
||||||
public Map<String, SimpleEntity> getOneToManyByBasic() {
|
|
||||||
return oneToManyByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOneToManyByBasic(Map<String, SimpleEntity> oneToManyByBasic) {
|
|
||||||
this.oneToManyByBasic = oneToManyByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addOneToManyByBasic(String key, SimpleEntity val) {
|
|
||||||
if ( oneToManyByBasic == null ) {
|
|
||||||
oneToManyByBasic = new HashMap<>();
|
|
||||||
}
|
|
||||||
oneToManyByBasic.put( key, val );
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo (6.0) : add support for using an entity as map key
|
|
||||||
// see `org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper#interpretMapKey`
|
|
||||||
@ElementCollection
|
|
||||||
public Map<SimpleEntity, String> getBasicByOneToMany() {
|
|
||||||
return basicByOneToMany;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicByOneToMany(Map<SimpleEntity, String> basicByOneToMany) {
|
|
||||||
this.basicByOneToMany = basicByOneToMany;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addOneToManyByBasic(SimpleEntity key, String val) {
|
|
||||||
if ( basicByOneToMany == null ) {
|
|
||||||
basicByOneToMany = new HashMap<>();
|
|
||||||
}
|
|
||||||
basicByOneToMany.put( key, val );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToMany
|
|
||||||
@CollectionTable( name = "m2m_by_basic" )
|
|
||||||
public Map<String, SimpleEntity> getManyToManyByBasic() {
|
|
||||||
return manyToManyByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setManyToManyByBasic(Map<String, SimpleEntity> manyToManyByBasic) {
|
|
||||||
this.manyToManyByBasic = manyToManyByBasic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addManyToManyByBasic(String key, SimpleEntity val) {
|
|
||||||
if ( manyToManyByBasic == null ) {
|
|
||||||
manyToManyByBasic = new HashMap<>();
|
|
||||||
}
|
|
||||||
manyToManyByBasic.put( key, val );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* 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.orm.test.metamodel.mapping.collections;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.CollectionTable;
|
|
||||||
import javax.persistence.Convert;
|
|
||||||
import javax.persistence.ElementCollection;
|
|
||||||
import javax.persistence.Embedded;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
import org.hibernate.annotations.SortNatural;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
@Entity(name = "EntityContainingSets")
|
|
||||||
@Table(name = "entity_containing_sets")
|
|
||||||
public class EntityContainingSets {
|
|
||||||
private Integer id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private Set<String> setOfBasics;
|
|
||||||
private Set<EnumValue> setOfConvertedBasics;
|
|
||||||
private Set<EnumValue> setOfEnums;
|
|
||||||
private Set<SomeStuff> setOfComponents;
|
|
||||||
private Set<SimpleEntity> setOfEntities;
|
|
||||||
|
|
||||||
private SortedSet<String> sortedSetOfBasics;
|
|
||||||
|
|
||||||
public EntityContainingSets() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityContainingSets(Integer id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
public Set<String> getSetOfBasics() {
|
|
||||||
return setOfBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfBasics(Set<String> setOfBasics) {
|
|
||||||
this.setOfBasics = setOfBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addBasic(String value) {
|
|
||||||
if ( setOfBasics == null ) {
|
|
||||||
setOfBasics = new HashSet<>();
|
|
||||||
}
|
|
||||||
setOfBasics.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@Convert(converter = EnumValueConverter.class)
|
|
||||||
public Set<EnumValue> getSetOfConvertedBasics() {
|
|
||||||
return setOfConvertedBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfConvertedBasics(Set<EnumValue> setOfConvertedBasics) {
|
|
||||||
this.setOfConvertedBasics = setOfConvertedBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addConvertedBasic(EnumValue value) {
|
|
||||||
if ( setOfConvertedBasics == null ) {
|
|
||||||
setOfConvertedBasics = new HashSet<>();
|
|
||||||
}
|
|
||||||
setOfConvertedBasics.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
public Set<EnumValue> getSetOfEnums() {
|
|
||||||
return setOfEnums;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfEnums(Set<EnumValue> setOfEnums) {
|
|
||||||
this.setOfEnums = setOfEnums;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEnum(EnumValue value) {
|
|
||||||
if ( setOfEnums == null ) {
|
|
||||||
setOfEnums = new HashSet<>();
|
|
||||||
}
|
|
||||||
setOfEnums.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
@Embedded
|
|
||||||
public Set<SomeStuff> getSetOfComponents() {
|
|
||||||
return setOfComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfComponents(Set<SomeStuff> setOfComponents) {
|
|
||||||
this.setOfComponents = setOfComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addComponent(SomeStuff value) {
|
|
||||||
if ( setOfComponents == null ) {
|
|
||||||
setOfComponents = new HashSet<>();
|
|
||||||
}
|
|
||||||
setOfComponents.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL)
|
|
||||||
public Set<SimpleEntity> getSetOfEntities() {
|
|
||||||
return setOfEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfEntities(Set<SimpleEntity> setOfEntities) {
|
|
||||||
this.setOfEntities = setOfEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSimpleEntity(SimpleEntity value) {
|
|
||||||
if ( setOfEntities == null ) {
|
|
||||||
setOfEntities = new HashSet<>();
|
|
||||||
}
|
|
||||||
setOfEntities.add( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection()
|
|
||||||
@CollectionTable( name = "EntityOfSet_sortedBasics")
|
|
||||||
@SortNatural
|
|
||||||
public SortedSet<String> getSortedSetOfBasics() {
|
|
||||||
return sortedSetOfBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSortedSetOfBasics(SortedSet<String> sortedSetOfBasics) {
|
|
||||||
this.sortedSetOfBasics = sortedSetOfBasics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSortedBasic(String value) {
|
|
||||||
if ( sortedSetOfBasics == null ) {
|
|
||||||
sortedSetOfBasics = new TreeSet<>();
|
|
||||||
}
|
|
||||||
sortedSetOfBasics.add( value );
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* 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.orm.test.metamodel.mapping.collections;
|
||||||
|
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
import org.hibernate.collection.spi.PersistentCollection;
|
||||||
|
import org.hibernate.query.spi.QueryImplementor;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EntityOfLists;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EnumValue;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.SimpleComponent;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.SimpleEntity;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
|
||||||
|
@ServiceRegistry
|
||||||
|
@SessionFactory
|
||||||
|
public class ListOperationTests {
|
||||||
|
@BeforeEach
|
||||||
|
public void createTestData(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
final EntityOfLists entityContainingLists = new EntityOfLists( 1, "first" );
|
||||||
|
|
||||||
|
entityContainingLists.addBasic( "abc" );
|
||||||
|
entityContainingLists.addBasic( "def" );
|
||||||
|
entityContainingLists.addBasic( "ghi" );
|
||||||
|
|
||||||
|
entityContainingLists.addConvertedEnum( EnumValue.TWO );
|
||||||
|
|
||||||
|
entityContainingLists.addEnum( EnumValue.ONE );
|
||||||
|
entityContainingLists.addEnum( EnumValue.THREE );
|
||||||
|
|
||||||
|
entityContainingLists.addComponent( new SimpleComponent( "first-a1", "first-another-a1" ) );
|
||||||
|
entityContainingLists.addComponent( new SimpleComponent( "first-a2", "first-another-a2" ) );
|
||||||
|
|
||||||
|
session.save( entityContainingLists );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void dropTestData(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
session.createQuery( "delete from EntityOfLists" ).executeUpdate();
|
||||||
|
session.createQuery( "delete from SimpleEntity" ).executeUpdate();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void listBaselineTest(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
final QueryImplementor<EntityOfLists> query = session.createQuery(
|
||||||
|
"select e from EntityOfLists e",
|
||||||
|
EntityOfLists.class
|
||||||
|
);
|
||||||
|
final EntityOfLists result = query.uniqueResult();
|
||||||
|
|
||||||
|
assertThat( result, notNullValue() );
|
||||||
|
assertThat( result.getListOfBasics(), notNullValue() );
|
||||||
|
assertThat( Hibernate.isInitialized( result.getListOfBasics() ), is( false ) );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void listEagerBasicTest(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
final QueryImplementor<EntityOfLists> query = session.createQuery(
|
||||||
|
"select e from EntityOfLists e join fetch e.listOfBasics",
|
||||||
|
EntityOfLists.class
|
||||||
|
);
|
||||||
|
final EntityOfLists result = query.uniqueResult();
|
||||||
|
|
||||||
|
assertThat( result, notNullValue() );
|
||||||
|
|
||||||
|
assertThat( result.getListOfBasics(), notNullValue() );
|
||||||
|
assertThat( Hibernate.isInitialized( result.getListOfBasics() ), is( true ) );
|
||||||
|
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfBasics() ) );
|
||||||
|
assertThat( result.getListOfBasics().size(), is( 3 ) );
|
||||||
|
|
||||||
|
assertThat( result.getListOfConvertedEnums(), notNullValue() );
|
||||||
|
assertThat( Hibernate.isInitialized( result.getListOfConvertedEnums() ), is( false ) );
|
||||||
|
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfConvertedEnums() ) );
|
||||||
|
|
||||||
|
assertThat( result.getListOfEnums(), notNullValue() );
|
||||||
|
assertThat( Hibernate.isInitialized( result.getListOfEnums() ), is( false ) );
|
||||||
|
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfEnums() ) );
|
||||||
|
|
||||||
|
assertThat( result.getListOfComponents(), notNullValue() );
|
||||||
|
assertThat( Hibernate.isInitialized( result.getListOfComponents() ), is( false ) );
|
||||||
|
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfComponents() ) );
|
||||||
|
|
||||||
|
assertThat( result.getListOfOneToMany(), notNullValue() );
|
||||||
|
assertThat( Hibernate.isInitialized( result.getListOfOneToMany() ), is( false ) );
|
||||||
|
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfOneToMany() ) );
|
||||||
|
|
||||||
|
assertThat( result.getListOfManyToMany(), notNullValue() );
|
||||||
|
assertThat( Hibernate.isInitialized( result.getListOfManyToMany() ), is( false ) );
|
||||||
|
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfManyToMany() ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -8,9 +8,12 @@
|
|||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EntityOfMaps;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EnumValue;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.SimpleComponent;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.DomainModelScope;
|
import org.hibernate.testing.orm.junit.DomainModelScope;
|
||||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
|
||||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
@ -22,13 +25,7 @@
|
|||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
@DomainModel(
|
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
|
||||||
annotatedClasses = {
|
|
||||||
SimpleEntity.class,
|
|
||||||
EntityContainingMaps.class,
|
|
||||||
SomeStuff.class
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ServiceRegistry
|
@ServiceRegistry
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
public class MapOperationTests {
|
public class MapOperationTests {
|
||||||
@ -36,7 +33,7 @@ public class MapOperationTests {
|
|||||||
public void createData(SessionFactoryScope scope) {
|
public void createData(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingMaps entityContainingMaps = new EntityContainingMaps( 1, "first-map-entity" );
|
final EntityOfMaps entityContainingMaps = new EntityOfMaps( 1, "first-map-entity" );
|
||||||
entityContainingMaps.addBasicByBasic( "someKey", "someValue" );
|
entityContainingMaps.addBasicByBasic( "someKey", "someValue" );
|
||||||
entityContainingMaps.addBasicByBasic( "anotherKey", "anotherValue" );
|
entityContainingMaps.addBasicByBasic( "anotherKey", "anotherValue" );
|
||||||
|
|
||||||
@ -45,8 +42,8 @@ public void createData(SessionFactoryScope scope) {
|
|||||||
|
|
||||||
entityContainingMaps.addBasicByConvertedEnum( EnumValue.THREE, "three" );
|
entityContainingMaps.addBasicByConvertedEnum( EnumValue.THREE, "three" );
|
||||||
|
|
||||||
entityContainingMaps.addSomeStuffByBasic( "the stuff", new SomeStuff( "the stuff - 1", "the stuff - 2" ) );
|
entityContainingMaps.addComponentByBasic( "the stuff", new SimpleComponent( "the stuff - 1", "the stuff - 2" ) );
|
||||||
entityContainingMaps.addSomeStuffByBasic( "the other stuff", new SomeStuff( "the other stuff - 1", "the other stuff - 2" ) );
|
entityContainingMaps.addComponentByBasic( "the other stuff", new SimpleComponent( "the other stuff - 1", "the other stuff - 2" ) );
|
||||||
|
|
||||||
session.save( entityContainingMaps );
|
session.save( entityContainingMaps );
|
||||||
}
|
}
|
||||||
@ -60,7 +57,7 @@ public void dropData(SessionFactoryScope scope, DomainModelScope domainModelScop
|
|||||||
|
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingMaps entity = session.load( EntityContainingMaps.class, 1 );
|
final EntityOfMaps entity = session.load( EntityOfMaps.class, 1 );
|
||||||
session.delete( entity );
|
session.delete( entity );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -74,9 +71,9 @@ public void dropData(SessionFactoryScope scope, DomainModelScope domainModelScop
|
|||||||
public void testSqmFetching(SessionFactoryScope scope) {
|
public void testSqmFetching(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingMaps entity = session.createQuery(
|
final EntityOfMaps entity = session.createQuery(
|
||||||
"select e from EntityContainingMaps e join fetch e.basicByEnum",
|
"select e from EntityOfMaps e join fetch e.basicByEnum",
|
||||||
EntityContainingMaps.class
|
EntityOfMaps.class
|
||||||
).getSingleResult();
|
).getSingleResult();
|
||||||
|
|
||||||
assert Hibernate.isInitialized( entity.getBasicByEnum() );
|
assert Hibernate.isInitialized( entity.getBasicByEnum() );
|
||||||
@ -90,9 +87,9 @@ public void testSqmFetching(SessionFactoryScope scope) {
|
|||||||
public void testDelete(SessionFactoryScope scope) {
|
public void testDelete(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingMaps entity = session.createQuery(
|
final EntityOfMaps entity = session.createQuery(
|
||||||
"select e from EntityContainingMaps e join fetch e.basicByEnum",
|
"select e from EntityOfMaps e join fetch e.basicByEnum",
|
||||||
EntityContainingMaps.class
|
EntityOfMaps.class
|
||||||
).getSingleResult();
|
).getSingleResult();
|
||||||
|
|
||||||
session.delete( entity );
|
session.delete( entity );
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.metamodel.spi.DomainMetamodel;
|
import org.hibernate.metamodel.spi.DomainMetamodel;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EntityOfSets;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EntityOfMaps;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EntityOfLists;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
@ -24,15 +28,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@DomainModel(
|
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
|
||||||
annotatedClasses = {
|
|
||||||
SimpleEntity.class,
|
|
||||||
EntityContainingLists.class,
|
|
||||||
EntityContainingSets.class,
|
|
||||||
EntityContainingMaps.class,
|
|
||||||
SomeStuff.class
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ServiceRegistry
|
@ServiceRegistry
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
@ -41,58 +37,65 @@ public class PluralAttributeMappingTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testLists(SessionFactoryScope scope) {
|
public void testLists(SessionFactoryScope scope) {
|
||||||
final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel();
|
final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel();
|
||||||
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityContainingLists.class );
|
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityOfLists.class );
|
||||||
|
|
||||||
assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 6 ) );
|
assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 7 ) );
|
||||||
|
|
||||||
final AttributeMapping listOfBasics = containerEntityDescriptor.findAttributeMapping( "listOfBasics" );
|
final AttributeMapping listOfBasics = containerEntityDescriptor.findAttributeMapping( "listOfBasics" );
|
||||||
assertThat( listOfBasics, notNullValue() );
|
assertThat( listOfBasics, notNullValue() );
|
||||||
|
|
||||||
final AttributeMapping listOfConvertedBasics = containerEntityDescriptor.findAttributeMapping( "listOfConvertedBasics" );
|
|
||||||
assertThat( listOfConvertedBasics, notNullValue() );
|
|
||||||
|
|
||||||
|
|
||||||
final AttributeMapping listOfEnums = containerEntityDescriptor.findAttributeMapping( "listOfEnums" );
|
final AttributeMapping listOfEnums = containerEntityDescriptor.findAttributeMapping( "listOfEnums" );
|
||||||
assertThat( listOfEnums, notNullValue() );
|
assertThat( listOfEnums, notNullValue() );
|
||||||
|
|
||||||
|
final AttributeMapping listOfConvertedBasics = containerEntityDescriptor.findAttributeMapping( "listOfConvertedEnums" );
|
||||||
|
assertThat( listOfConvertedBasics, notNullValue() );
|
||||||
|
|
||||||
final AttributeMapping listOfComponents = containerEntityDescriptor.findAttributeMapping( "listOfComponents" );
|
final AttributeMapping listOfComponents = containerEntityDescriptor.findAttributeMapping( "listOfComponents" );
|
||||||
assertThat( listOfComponents, notNullValue() );
|
assertThat( listOfComponents, notNullValue() );
|
||||||
|
|
||||||
final AttributeMapping listOfEntities = containerEntityDescriptor.findAttributeMapping( "listOfEntities" );
|
final AttributeMapping listOfOneToMany = containerEntityDescriptor.findAttributeMapping( "listOfOneToMany" );
|
||||||
assertThat( listOfEntities, notNullValue() );
|
assertThat( listOfOneToMany, notNullValue() );
|
||||||
|
|
||||||
|
final AttributeMapping listOfManyToMany = containerEntityDescriptor.findAttributeMapping( "listOfManyToMany" );
|
||||||
|
assertThat( listOfManyToMany, notNullValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSets(SessionFactoryScope scope) {
|
public void testSets(SessionFactoryScope scope) {
|
||||||
final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel();
|
final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel();
|
||||||
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityContainingSets.class );
|
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityOfSets.class );
|
||||||
|
|
||||||
assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 7 ) );
|
assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 9 ) );
|
||||||
|
|
||||||
final AttributeMapping setOfBasics = containerEntityDescriptor.findAttributeMapping( "setOfBasics" );
|
final AttributeMapping setOfBasics = containerEntityDescriptor.findAttributeMapping( "setOfBasics" );
|
||||||
assertThat( setOfBasics, notNullValue() );
|
assertThat( setOfBasics, notNullValue() );
|
||||||
|
|
||||||
final AttributeMapping setOfConvertedBasics = containerEntityDescriptor.findAttributeMapping( "setOfConvertedBasics" );
|
final AttributeMapping sortedSetOfBasics = containerEntityDescriptor.findAttributeMapping( "sortedSetOfBasics" );
|
||||||
assertThat( setOfConvertedBasics, notNullValue() );
|
assertThat( sortedSetOfBasics, notNullValue() );
|
||||||
|
|
||||||
|
|
||||||
final AttributeMapping setOfEnums = containerEntityDescriptor.findAttributeMapping( "setOfEnums" );
|
final AttributeMapping setOfEnums = containerEntityDescriptor.findAttributeMapping( "setOfEnums" );
|
||||||
assertThat( setOfEnums, notNullValue() );
|
assertThat( setOfEnums, notNullValue() );
|
||||||
|
|
||||||
|
final AttributeMapping setOfConvertedBasics = containerEntityDescriptor.findAttributeMapping( "setOfConvertedEnums" );
|
||||||
|
assertThat( setOfConvertedBasics, notNullValue() );
|
||||||
|
|
||||||
final AttributeMapping setOfComponents = containerEntityDescriptor.findAttributeMapping( "setOfComponents" );
|
final AttributeMapping setOfComponents = containerEntityDescriptor.findAttributeMapping( "setOfComponents" );
|
||||||
assertThat( setOfComponents, notNullValue() );
|
assertThat( setOfComponents, notNullValue() );
|
||||||
|
|
||||||
final AttributeMapping setOfEntities = containerEntityDescriptor.findAttributeMapping( "setOfEntities" );
|
final AttributeMapping extraLazySetOfComponents = containerEntityDescriptor.findAttributeMapping( "extraLazySetOfComponents" );
|
||||||
assertThat( setOfEntities, notNullValue() );
|
assertThat( extraLazySetOfComponents, notNullValue() );
|
||||||
|
|
||||||
final AttributeMapping sortedSetOfBasics = containerEntityDescriptor.findAttributeMapping( "sortedSetOfBasics" );
|
final AttributeMapping setOfOneToMany = containerEntityDescriptor.findAttributeMapping( "setOfOneToMany" );
|
||||||
assertThat( sortedSetOfBasics, notNullValue() );
|
assertThat( setOfOneToMany, notNullValue() );
|
||||||
|
|
||||||
|
final AttributeMapping setOfManyToMany = containerEntityDescriptor.findAttributeMapping( "setOfManyToMany" );
|
||||||
|
assertThat( setOfManyToMany, notNullValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMaps(SessionFactoryScope scope) {
|
public void testMaps(SessionFactoryScope scope) {
|
||||||
final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel();
|
final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel();
|
||||||
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityContainingMaps.class );
|
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityOfMaps.class );
|
||||||
|
|
||||||
// 8 for now, until entity-valued map keys is supported
|
// 8 for now, until entity-valued map keys is supported
|
||||||
assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 9 ) );
|
assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 9 ) );
|
||||||
@ -112,12 +115,12 @@ public void testMaps(SessionFactoryScope scope) {
|
|||||||
assertThat( basicByConvertedEnum.getKeyDescriptor(), notNullValue() );
|
assertThat( basicByConvertedEnum.getKeyDescriptor(), notNullValue() );
|
||||||
assertThat( basicByConvertedEnum.getElementDescriptor(), notNullValue() );
|
assertThat( basicByConvertedEnum.getElementDescriptor(), notNullValue() );
|
||||||
|
|
||||||
final PluralAttributeMapping someStuffByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping( "someStuffByBasic" );
|
final PluralAttributeMapping someStuffByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping( "componentByBasic" );
|
||||||
assertThat( someStuffByBasic, notNullValue() );
|
assertThat( someStuffByBasic, notNullValue() );
|
||||||
assertThat( someStuffByBasic.getKeyDescriptor(), notNullValue() );
|
assertThat( someStuffByBasic.getKeyDescriptor(), notNullValue() );
|
||||||
assertThat( someStuffByBasic.getElementDescriptor(), notNullValue() );
|
assertThat( someStuffByBasic.getElementDescriptor(), notNullValue() );
|
||||||
|
|
||||||
final PluralAttributeMapping basicBySomeStuff = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping( "basicBySomeStuff" );
|
final PluralAttributeMapping basicBySomeStuff = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping( "basicByComponent" );
|
||||||
assertThat( basicBySomeStuff, notNullValue() );
|
assertThat( basicBySomeStuff, notNullValue() );
|
||||||
assertThat( basicBySomeStuff.getKeyDescriptor(), notNullValue() );
|
assertThat( basicBySomeStuff.getKeyDescriptor(), notNullValue() );
|
||||||
assertThat( basicBySomeStuff.getElementDescriptor(), notNullValue() );
|
assertThat( basicBySomeStuff.getElementDescriptor(), notNullValue() );
|
||||||
|
@ -10,9 +10,14 @@
|
|||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
|
import org.hibernate.testing.hamcrest.CollectionMatchers;
|
||||||
|
import org.hibernate.testing.hamcrest.InitializationCheckMatcher;
|
||||||
|
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EntityOfSets;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EnumValue;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.SimpleComponent;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.DomainModelScope;
|
import org.hibernate.testing.orm.junit.DomainModelScope;
|
||||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
|
||||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
@ -20,21 +25,15 @@
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
@DomainModel(
|
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
|
||||||
annotatedClasses = {
|
|
||||||
SimpleEntity.class,
|
|
||||||
EntityContainingSets.class,
|
|
||||||
SomeStuff.class
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ServiceRegistry
|
@ServiceRegistry
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
public class SetOperationTests {
|
public class SetOperationTests {
|
||||||
@ -42,7 +41,7 @@ public class SetOperationTests {
|
|||||||
public void createData(SessionFactoryScope scope) {
|
public void createData(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = new EntityContainingSets( 1, "first-map-entity" );
|
final EntityOfSets entity = new EntityOfSets( 1, "first-map-entity" );
|
||||||
entity.addBasic( "a value" );
|
entity.addBasic( "a value" );
|
||||||
entity.addBasic( "another value" );
|
entity.addBasic( "another value" );
|
||||||
|
|
||||||
@ -52,11 +51,11 @@ public void createData(SessionFactoryScope scope) {
|
|||||||
entity.addEnum( EnumValue.ONE );
|
entity.addEnum( EnumValue.ONE );
|
||||||
entity.addEnum( EnumValue.TWO );
|
entity.addEnum( EnumValue.TWO );
|
||||||
|
|
||||||
entity.addConvertedBasic( EnumValue.ONE );
|
entity.addConvertedEnum( EnumValue.ONE );
|
||||||
entity.addConvertedBasic( EnumValue.THREE );
|
entity.addConvertedEnum( EnumValue.THREE );
|
||||||
|
|
||||||
entity.addComponent( new SomeStuff( "the stuff - 1", "the stuff - 2" ) );
|
entity.addComponent( new SimpleComponent( "the stuff - 1", "the stuff - 2" ) );
|
||||||
entity.addComponent( new SomeStuff( "other stuff - 1", "other stuff - 2" ) );
|
entity.addComponent( new SimpleComponent( "other stuff - 1", "other stuff - 2" ) );
|
||||||
|
|
||||||
session.save( entity );
|
session.save( entity );
|
||||||
}
|
}
|
||||||
@ -64,11 +63,10 @@ public void createData(SessionFactoryScope scope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void dropData(SessionFactoryScope scope, DomainModelScope domainModelScope) {
|
public void dropData(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = session.load( EntityContainingSets.class, 1 );
|
session.createQuery( "delete from EntityOfSets where name is not null" ).executeUpdate();
|
||||||
session.delete( entity );
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -77,9 +75,9 @@ public void dropData(SessionFactoryScope scope, DomainModelScope domainModelScop
|
|||||||
public void testLoad(SessionFactoryScope scope) {
|
public void testLoad(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = session.load( EntityContainingSets.class, 1 );
|
final EntityOfSets entity = session.load( EntityOfSets.class, 1 );
|
||||||
assertThat( entity, is( notNullValue() ) );
|
assertThat( entity, is( notNullValue() ) );
|
||||||
assertThat( Hibernate.isInitialized( entity ), is( false ) );
|
assertThat( entity, InitializationCheckMatcher.isNotInitialized() );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -88,10 +86,24 @@ public void testLoad(SessionFactoryScope scope) {
|
|||||||
public void testGet(SessionFactoryScope scope) {
|
public void testGet(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = session.get( EntityContainingSets.class, 1 );
|
final EntityOfSets entity = session.get( EntityOfSets.class, 1 );
|
||||||
assertThat( entity, is( notNullValue() ) );
|
assertThat( entity, is( notNullValue() ) );
|
||||||
assertThat( Hibernate.isInitialized( entity ), is( true ) );
|
assertThat( entity, InitializationCheckMatcher.isInitialized() );
|
||||||
assertThat( Hibernate.isInitialized( entity.getSetOfBasics() ), is( false ) );
|
assertThat( entity.getSetOfBasics(), InitializationCheckMatcher.isNotInitialized() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSqm(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
final EntityOfSets entity = session.createQuery(
|
||||||
|
"select e from EntityOfSets e",
|
||||||
|
EntityOfSets.class
|
||||||
|
).getSingleResult();
|
||||||
|
|
||||||
|
assertThat( entity.getSetOfBasics(), InitializationCheckMatcher.isNotInitialized() );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -100,12 +112,12 @@ public void testGet(SessionFactoryScope scope) {
|
|||||||
public void testSqmFetch(SessionFactoryScope scope) {
|
public void testSqmFetch(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = session.createQuery(
|
final EntityOfSets entity = session.createQuery(
|
||||||
"select e from EntityContainingSets e join fetch e.setOfBasics",
|
"select e from EntityOfSets e join fetch e.setOfBasics",
|
||||||
EntityContainingSets.class
|
EntityOfSets.class
|
||||||
).getSingleResult();
|
).getSingleResult();
|
||||||
|
|
||||||
assert Hibernate.isInitialized( entity.getSetOfBasics() );
|
assertThat( entity.getSetOfBasics(), InitializationCheckMatcher.isInitialized() );
|
||||||
|
|
||||||
assert entity.getSetOfBasics().size() == 2;
|
assert entity.getSetOfBasics().size() == 2;
|
||||||
}
|
}
|
||||||
@ -116,7 +128,7 @@ public void testSqmFetch(SessionFactoryScope scope) {
|
|||||||
public void testDeleteWithElementCollectionData(SessionFactoryScope scope) {
|
public void testDeleteWithElementCollectionData(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = session.load( EntityContainingSets.class, 1 );
|
final EntityOfSets entity = session.load( EntityOfSets.class, 1 );
|
||||||
session.delete( entity );
|
session.delete( entity );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -129,14 +141,14 @@ public void testDeleteWithElementCollectionData(SessionFactoryScope scope) {
|
|||||||
public void testTriggerFetch(SessionFactoryScope scope) {
|
public void testTriggerFetch(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = session.get( EntityContainingSets.class, 1 );
|
final EntityOfSets entity = session.get( EntityOfSets.class, 1 );
|
||||||
assert ! Hibernate.isInitialized( entity.getSetOfBasics() );
|
assertThat( entity.getSetOfBasics(), InitializationCheckMatcher.isNotInitialized() );
|
||||||
|
|
||||||
|
// trigger the init
|
||||||
assertThat( entity.getSetOfBasics().size(), is( 2 ) );
|
assertThat( entity.getSetOfBasics().size(), is( 2 ) );
|
||||||
|
|
||||||
assert Hibernate.isInitialized( entity.getSetOfBasics() );
|
assertThat( entity.getSetOfBasics(), InitializationCheckMatcher.isInitialized() );
|
||||||
|
assertThat( entity.getSetOfEnums(), InitializationCheckMatcher.isNotInitialized() );
|
||||||
assert ! Hibernate.isInitialized( entity.getSetOfEnums() );
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -145,12 +157,14 @@ public void testTriggerFetch(SessionFactoryScope scope) {
|
|||||||
public void testSortedSetAccess(SessionFactoryScope scope) {
|
public void testSortedSetAccess(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final EntityContainingSets entity = session.get( EntityContainingSets.class, 1 );
|
final EntityOfSets entity = session.get( EntityOfSets.class, 1 );
|
||||||
assert ! Hibernate.isInitialized( entity.getSortedSetOfBasics() );
|
assertThat( entity.getSortedSetOfBasics(), InitializationCheckMatcher.isNotInitialized() );
|
||||||
|
|
||||||
|
// trigger the init
|
||||||
Hibernate.initialize( entity.getSortedSetOfBasics() );
|
Hibernate.initialize( entity.getSortedSetOfBasics() );
|
||||||
|
assertThat( entity.getSortedSetOfBasics(), InitializationCheckMatcher.isInitialized() );
|
||||||
assertThat( entity.getSortedSetOfBasics().size(), is( 2 ) );
|
assertThat( entity.getSortedSetOfBasics().size(), is( 2 ) );
|
||||||
|
assertThat( entity.getSetOfEnums(), InitializationCheckMatcher.isNotInitialized() );
|
||||||
|
|
||||||
final Iterator<String> iterator = entity.getSortedSetOfBasics().iterator();
|
final Iterator<String> iterator = entity.getSortedSetOfBasics().iterator();
|
||||||
final String first = iterator.next();
|
final String first = iterator.next();
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* 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.orm.test.metamodel.mapping.collections;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
@Entity(name = "SimpleEntity")
|
|
||||||
@Table(name = "simple_entity")
|
|
||||||
public class SimpleEntity {
|
|
||||||
private Integer id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public SimpleEntity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public SimpleEntity(Integer id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* 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.orm.test.metamodel.mapping.collections;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
|
||||||
import org.hibernate.tool.schema.SourceType;
|
|
||||||
import org.hibernate.tool.schema.TargetType;
|
|
||||||
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
|
||||||
import org.hibernate.tool.schema.spi.ExceptionHandler;
|
|
||||||
import org.hibernate.tool.schema.spi.ExecutionOptions;
|
|
||||||
import org.hibernate.tool.schema.spi.SchemaManagementTool;
|
|
||||||
import org.hibernate.tool.schema.spi.ScriptSourceInput;
|
|
||||||
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
|
|
||||||
import org.hibernate.tool.schema.spi.SourceDescriptor;
|
|
||||||
import org.hibernate.tool.schema.spi.TargetDescriptor;
|
|
||||||
|
|
||||||
import org.hibernate.testing.orm.junit.DomainModelScope;
|
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class TempDropDataHelper {
|
|
||||||
static void cleanDatabaseSchema(SessionFactoryScope scope, DomainModelScope domainModelScope) {
|
|
||||||
final ServiceRegistryImplementor serviceRegistry = scope.getSessionFactory().getServiceRegistry();
|
|
||||||
final SchemaManagementTool schemaTool = serviceRegistry.getService( SchemaManagementTool.class );
|
|
||||||
|
|
||||||
final ExecutionOptions executionOptions = new ExecutionOptions() {
|
|
||||||
@Override
|
|
||||||
public Map getConfigurationValues() {
|
|
||||||
return scope.getSessionFactory().getProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldManageNamespaces() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExceptionHandler getExceptionHandler() {
|
|
||||||
return new ExceptionHandler() {
|
|
||||||
@Override
|
|
||||||
public void handleException(CommandAcceptanceException exception) {
|
|
||||||
throw exception;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final SourceDescriptor sourceDescriptor = new SourceDescriptor() {
|
|
||||||
@Override
|
|
||||||
public SourceType getSourceType() {
|
|
||||||
return SourceType.METADATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ScriptSourceInput getScriptSourceInput() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final TargetDescriptor targetDescriptor = new TargetDescriptor() {
|
|
||||||
@Override
|
|
||||||
public EnumSet<TargetType> getTargetTypes() {
|
|
||||||
return EnumSet.of( TargetType.DATABASE );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ScriptTargetOutput getScriptTargetOutput() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
schemaTool.getSchemaDropper( scope.getSessionFactory().getProperties() ).doDrop(
|
|
||||||
domainModelScope.getDomainModel(),
|
|
||||||
executionOptions,
|
|
||||||
sourceDescriptor,
|
|
||||||
targetDescriptor
|
|
||||||
);
|
|
||||||
|
|
||||||
schemaTool.getSchemaCreator( scope.getSessionFactory().getProperties() ).doCreation(
|
|
||||||
domainModelScope.getDomainModel(),
|
|
||||||
executionOptions,
|
|
||||||
sourceDescriptor,
|
|
||||||
targetDescriptor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,6 +32,7 @@
|
|||||||
import org.hibernate.testing.orm.domain.gambit.EntityOfLists;
|
import org.hibernate.testing.orm.domain.gambit.EntityOfLists;
|
||||||
import org.hibernate.testing.orm.domain.gambit.EntityOfMaps;
|
import org.hibernate.testing.orm.domain.gambit.EntityOfMaps;
|
||||||
import org.hibernate.testing.orm.domain.gambit.EntityOfSets;
|
import org.hibernate.testing.orm.domain.gambit.EntityOfSets;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.SimpleEntity;
|
||||||
import org.hibernate.testing.orm.junit.TestingUtil;
|
import org.hibernate.testing.orm.junit.TestingUtil;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -150,13 +151,13 @@ public void testBinaryArithmeticExpressionWithMultipleFromSpaces() {
|
|||||||
@Test
|
@Test
|
||||||
public void testMapKeyFunction() {
|
public void testMapKeyFunction() {
|
||||||
collectionIndexFunctionAssertions(
|
collectionIndexFunctionAssertions(
|
||||||
interpretSelect( "select key(m) from EntityOfMaps e join e.basicToBasicMap m" ),
|
interpretSelect( "select key(m) from EntityOfMaps e join e.basicByBasic m" ),
|
||||||
CollectionClassification.MAP,
|
CollectionClassification.MAP,
|
||||||
BasicDomainType.class,
|
BasicDomainType.class,
|
||||||
"m"
|
"m"
|
||||||
);
|
);
|
||||||
collectionIndexFunctionAssertions(
|
collectionIndexFunctionAssertions(
|
||||||
interpretSelect( "select key(m) from EntityOfMaps e join e.componentToBasicMap m" ),
|
interpretSelect( "select key(m) from EntityOfMaps e join e.basicByComponent m" ),
|
||||||
CollectionClassification.MAP,
|
CollectionClassification.MAP,
|
||||||
EmbeddableDomainType.class,
|
EmbeddableDomainType.class,
|
||||||
"m"
|
"m"
|
||||||
@ -194,18 +195,18 @@ private void collectionIndexFunctionAssertions(
|
|||||||
@Test
|
@Test
|
||||||
public void testMapValueFunction() {
|
public void testMapValueFunction() {
|
||||||
collectionValueFunctionAssertions(
|
collectionValueFunctionAssertions(
|
||||||
interpretSelect( "select value(m) from EntityOfMaps e join e.basicToBasicMap m" ),
|
interpretSelect( "select value(m) from EntityOfMaps e join e.basicByBasic m" ),
|
||||||
EntityOfMaps.class.getName() + ".basicToBasicMap",
|
EntityOfMaps.class.getName() + ".basicByBasic",
|
||||||
"m"
|
"m"
|
||||||
);
|
);
|
||||||
collectionValueFunctionAssertions(
|
collectionValueFunctionAssertions(
|
||||||
interpretSelect( "select value(m) from EntityOfMaps e join e.basicToComponentMap m" ),
|
interpretSelect( "select value(m) from EntityOfMaps e join e.componentByBasic m" ),
|
||||||
EntityOfMaps.class.getName() + ".basicToComponentMap",
|
EntityOfMaps.class.getName() + ".componentByBasic",
|
||||||
"m"
|
"m"
|
||||||
);
|
);
|
||||||
collectionValueFunctionAssertions(
|
collectionValueFunctionAssertions(
|
||||||
interpretSelect( "select value(m) from EntityOfMaps e join e.basicToOneToMany m" ),
|
interpretSelect( "select value(m) from EntityOfMaps e join e.oneToManyByBasic m" ),
|
||||||
EntityOfMaps.class.getName() + ".basicToOneToMany",
|
EntityOfMaps.class.getName() + ".oneToManyByBasic",
|
||||||
"m"
|
"m"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -284,7 +285,7 @@ private void collectionValueFunctionAssertions(
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapEntryFunction() {
|
public void testMapEntryFunction() {
|
||||||
SqmSelectStatement statement = interpretSelect( "select entry(m) from EntityOfMaps e join e.basicToManyToMany m" );
|
SqmSelectStatement statement = interpretSelect( "select entry(m) from EntityOfMaps e join e.manyToManyByBasic m" );
|
||||||
|
|
||||||
assertEquals( 1, statement.getQuerySpec().getSelectClause().getSelections().size() );
|
assertEquals( 1, statement.getQuerySpec().getSelectClause().getSelections().size() );
|
||||||
|
|
||||||
@ -321,6 +322,7 @@ protected Class[] getAnnotatedClasses() {
|
|||||||
EntityOfLists.class,
|
EntityOfLists.class,
|
||||||
EntityOfMaps.class,
|
EntityOfMaps.class,
|
||||||
EntityOfSets.class,
|
EntityOfSets.class,
|
||||||
|
SimpleEntity.class,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
import org.hibernate.testing.orm.domain.gambit.EntityOfLists;
|
import org.hibernate.testing.orm.domain.gambit.EntityOfLists;
|
||||||
import org.hibernate.testing.orm.domain.gambit.EntityOfMaps;
|
import org.hibernate.testing.orm.domain.gambit.EntityOfMaps;
|
||||||
import org.hibernate.testing.orm.domain.gambit.EntityOfSets;
|
import org.hibernate.testing.orm.domain.gambit.EntityOfSets;
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.SimpleEntity;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
@ -42,6 +43,7 @@ protected Class[] getAnnotatedClasses() {
|
|||||||
EntityOfLists.class,
|
EntityOfLists.class,
|
||||||
EntityOfSets.class,
|
EntityOfSets.class,
|
||||||
EntityOfMaps.class,
|
EntityOfMaps.class,
|
||||||
|
SimpleEntity.class,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* 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.orm.test.query.sqm.mutation.multitable;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.domain.StandardDomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
|
||||||
|
@ServiceRegistry
|
||||||
|
@SessionFactory( exportSchema = true )
|
||||||
|
public class BasicDeletionTests {
|
||||||
|
@BeforeEach
|
||||||
|
public void createTestData(SessionFactoryScope scope) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void dropTestData(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
session.createQuery( "delete from " ).executeUpdate();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,194 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* 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.orm.test.sql.exec;
|
|
||||||
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
|
||||||
import org.hibernate.collection.spi.PersistentCollection;
|
|
||||||
import org.hibernate.orm.test.metamodel.mapping.collections.SomeStuff;
|
|
||||||
import org.hibernate.orm.test.metamodel.mapping.collections.EntityContainingLists;
|
|
||||||
import org.hibernate.orm.test.metamodel.mapping.collections.EntityContainingSets;
|
|
||||||
import org.hibernate.orm.test.metamodel.mapping.collections.EnumValue;
|
|
||||||
import org.hibernate.orm.test.metamodel.mapping.collections.SimpleEntity;
|
|
||||||
import org.hibernate.query.spi.QueryImplementor;
|
|
||||||
|
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
|
||||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
|
||||||
import org.junit.jupiter.api.AfterAll;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
@DomainModel(
|
|
||||||
annotatedClasses = {
|
|
||||||
SimpleEntity.class,
|
|
||||||
EntityContainingLists.class,
|
|
||||||
EntityContainingSets.class,
|
|
||||||
SomeStuff.class
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ServiceRegistry
|
|
||||||
@SessionFactory
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public class PluralAttributeSmokeTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void listBaselineTest(SessionFactoryScope scope) {
|
|
||||||
scope.inTransaction(
|
|
||||||
session -> {
|
|
||||||
final QueryImplementor<EntityContainingLists> query = session.createQuery(
|
|
||||||
"select e from EntityContainingLists e",
|
|
||||||
EntityContainingLists.class
|
|
||||||
);
|
|
||||||
final EntityContainingLists result = query.uniqueResult();
|
|
||||||
|
|
||||||
assertThat( result, notNullValue() );
|
|
||||||
assertThat( result.getListOfBasics(), notNullValue() );
|
|
||||||
assertThat( Hibernate.isInitialized( result.getListOfBasics() ), is( false ) );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void listEagerBasicTest(SessionFactoryScope scope) {
|
|
||||||
scope.inTransaction(
|
|
||||||
session -> {
|
|
||||||
final QueryImplementor<EntityContainingLists> query = session.createQuery(
|
|
||||||
"select e from EntityContainingLists e join fetch e.listOfBasics",
|
|
||||||
EntityContainingLists.class
|
|
||||||
);
|
|
||||||
final EntityContainingLists result = query.uniqueResult();
|
|
||||||
|
|
||||||
assertThat( result, notNullValue() );
|
|
||||||
|
|
||||||
assertThat( result.getListOfBasics(), notNullValue() );
|
|
||||||
assertThat( Hibernate.isInitialized( result.getListOfBasics() ), is( true ) );
|
|
||||||
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfBasics() ) );
|
|
||||||
assertThat( result.getListOfBasics().size(), is( 3 ) );
|
|
||||||
|
|
||||||
assertThat( result.getListOfConvertedBasics(), notNullValue() );
|
|
||||||
assertThat( Hibernate.isInitialized( result.getListOfConvertedBasics() ), is( false ) );
|
|
||||||
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfConvertedBasics() ) );
|
|
||||||
|
|
||||||
assertThat( result.getListOfEnums(), notNullValue() );
|
|
||||||
assertThat( Hibernate.isInitialized( result.getListOfEnums() ), is( false ) );
|
|
||||||
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfEnums() ) );
|
|
||||||
|
|
||||||
assertThat( result.getListOfComponents(), notNullValue() );
|
|
||||||
assertThat( Hibernate.isInitialized( result.getListOfComponents() ), is( false ) );
|
|
||||||
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfComponents() ) );
|
|
||||||
|
|
||||||
assertThat( result.getListOfEntities(), notNullValue() );
|
|
||||||
assertThat( Hibernate.isInitialized( result.getListOfEntities() ), is( false ) );
|
|
||||||
assertTrue( session.getPersistenceContext().containsCollection( (PersistentCollection) result.getListOfEntities() ) );
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setBaselineTest(SessionFactoryScope scope) {
|
|
||||||
scope.inTransaction(
|
|
||||||
session -> {
|
|
||||||
final QueryImplementor<EntityContainingSets> query = session.createQuery(
|
|
||||||
"select e from EntityContainingSets e",
|
|
||||||
EntityContainingSets.class
|
|
||||||
);
|
|
||||||
|
|
||||||
final EntityContainingSets result = query.uniqueResult();
|
|
||||||
|
|
||||||
assertThat( result, notNullValue() );
|
|
||||||
assertThat( result.getSetOfBasics(), notNullValue() );
|
|
||||||
assertThat( Hibernate.isInitialized( result.getSetOfBasics() ), is( false ) );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public void createTestData(SessionFactoryScope scope) {
|
|
||||||
scope.inTransaction(
|
|
||||||
session -> {
|
|
||||||
final SimpleEntity simpleEntity1 = new SimpleEntity( 1, "simple-1" );
|
|
||||||
final SimpleEntity simpleEntity2 = new SimpleEntity( 2, "simple-2" );
|
|
||||||
|
|
||||||
session.save( simpleEntity1 );
|
|
||||||
session.save( simpleEntity2 );
|
|
||||||
|
|
||||||
{
|
|
||||||
final EntityContainingLists entityContainingLists = new EntityContainingLists( 1, "first" );
|
|
||||||
|
|
||||||
entityContainingLists.addBasic( "abc" );
|
|
||||||
entityContainingLists.addBasic( "def" );
|
|
||||||
entityContainingLists.addBasic( "ghi" );
|
|
||||||
|
|
||||||
entityContainingLists.addConvertedBasic( EnumValue.TWO );
|
|
||||||
|
|
||||||
entityContainingLists.addEnum( EnumValue.ONE );
|
|
||||||
entityContainingLists.addEnum( EnumValue.THREE );
|
|
||||||
|
|
||||||
entityContainingLists.addComponent( new SomeStuff( "first-a1", "first-another-a1" ) );
|
|
||||||
entityContainingLists.addComponent( new SomeStuff( "first-a2", "first-another-a2" ) );
|
|
||||||
|
|
||||||
entityContainingLists.addSimpleEntity( simpleEntity1 );
|
|
||||||
entityContainingLists.addSimpleEntity( simpleEntity2 );
|
|
||||||
|
|
||||||
session.save( entityContainingLists );
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final EntityContainingSets entity = new EntityContainingSets( 1, "first" );
|
|
||||||
|
|
||||||
entity.addBasic( "abc" );
|
|
||||||
entity.addBasic( "def" );
|
|
||||||
entity.addBasic( "ghi" );
|
|
||||||
|
|
||||||
entity.addConvertedBasic( EnumValue.TWO );
|
|
||||||
|
|
||||||
entity.addEnum( EnumValue.ONE );
|
|
||||||
entity.addEnum( EnumValue.THREE );
|
|
||||||
|
|
||||||
entity.addComponent( new SomeStuff( "first-a1", "first-another-a1" ) );
|
|
||||||
entity.addComponent( new SomeStuff( "first-a2", "first-another-a2" ) );
|
|
||||||
|
|
||||||
entity.addSimpleEntity( simpleEntity1 );
|
|
||||||
entity.addSimpleEntity( simpleEntity2 );
|
|
||||||
|
|
||||||
session.save( entity );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterAll
|
|
||||||
public void deleteTestData(SessionFactoryScope scope) {
|
|
||||||
scope.inTransaction(
|
|
||||||
session -> session.doWork(
|
|
||||||
conn -> {
|
|
||||||
try ( Statement stmnt = conn.createStatement() ) {
|
|
||||||
stmnt.execute( "delete from EntityContainingLists_listOfEnums" );
|
|
||||||
stmnt.execute( "delete from EntityContainingLists_listOfConvertedBasics" );
|
|
||||||
stmnt.execute( "delete from EntityContainingLists_listOfComponents" );
|
|
||||||
stmnt.execute( "delete from EntityContainingLists_listOfBasics" );
|
|
||||||
stmnt.execute( "delete from entity_containing_lists_simple_entity" );
|
|
||||||
stmnt.execute( "delete from entity_containing_lists" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,4 +28,22 @@ public static Matcher<Collection> isNotEmpty() {
|
|||||||
public static Matcher<Collection<?>> hasSize(int size) {
|
public static Matcher<Collection<?>> hasSize(int size) {
|
||||||
return org.hamcrest.Matchers.hasSize( size );
|
return org.hamcrest.Matchers.hasSize( size );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <X extends Collection<?>> HasNullElementsMatcher<X> hasNullElements() {
|
||||||
|
//noinspection unchecked
|
||||||
|
return HasNullElementsMatcher.HAS_NULL_ELEMENTS_MATCHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <X extends Collection<?>> HasNullElementsMatcher<X> hasNoNullElements() {
|
||||||
|
//noinspection unchecked
|
||||||
|
return HasNullElementsMatcher.HAS_NO_NULL_ELEMENTS_MATCHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <C extends Collection<?>> Matcher<C> isInitialized() {
|
||||||
|
return InitializationCheckMatcher.isInitialized();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <C extends Collection<?>> Matcher<C> isNotInitialized() {
|
||||||
|
return InitializationCheckMatcher.isNotInitialized();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* 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.testing.hamcrest;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.hamcrest.BaseMatcher;
|
||||||
|
import org.hamcrest.Description;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class HasNullElementsMatcher<C extends Collection<?>> extends BaseMatcher<C> {
|
||||||
|
public static final HasNullElementsMatcher HAS_NULL_ELEMENTS_MATCHER = new HasNullElementsMatcher( false );
|
||||||
|
public static final HasNullElementsMatcher HAS_NO_NULL_ELEMENTS_MATCHER = new HasNullElementsMatcher( true );
|
||||||
|
|
||||||
|
private final boolean negated;
|
||||||
|
|
||||||
|
public HasNullElementsMatcher(boolean negated) {
|
||||||
|
this.negated = negated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(Object item) {
|
||||||
|
assertThat( item, instanceOf( Collection.class ) );
|
||||||
|
|
||||||
|
//noinspection unchecked
|
||||||
|
C collection = (C) item;
|
||||||
|
|
||||||
|
if ( negated ) {
|
||||||
|
// check no-null-elements - if any is null, this check fails
|
||||||
|
collection.forEach( e -> assertThat( e, notNullValue() ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean foundOne = false;
|
||||||
|
for ( Object e : collection ) {
|
||||||
|
if ( e == null ) {
|
||||||
|
foundOne = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return foundOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void describeTo(Description description) {
|
||||||
|
description.appendText( "had null elements" );
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* 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.testing.hamcrest;
|
||||||
|
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
|
import org.hamcrest.BaseMatcher;
|
||||||
|
import org.hamcrest.Description;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
public class InitializationCheckMatcher<T> extends BaseMatcher<T> {
|
||||||
|
public static final InitializationCheckMatcher INITIALIZED_MATCHER = new InitializationCheckMatcher();
|
||||||
|
public static final InitializationCheckMatcher UNINITIALIZED_MATCHER = new InitializationCheckMatcher( false );
|
||||||
|
|
||||||
|
public static <T> InitializationCheckMatcher<T> isInitialized() {
|
||||||
|
//noinspection unchecked
|
||||||
|
return INITIALIZED_MATCHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Matcher<T> isNotInitialized() {
|
||||||
|
//noinspection unchecked
|
||||||
|
return UNINITIALIZED_MATCHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final boolean assertInitialized;
|
||||||
|
|
||||||
|
public InitializationCheckMatcher() {
|
||||||
|
this( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
public InitializationCheckMatcher(boolean assertInitialized) {
|
||||||
|
this.assertInitialized = assertInitialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(Object item) {
|
||||||
|
final boolean initialized = Hibernate.isInitialized( item );
|
||||||
|
return assertInitialized ? initialized : !initialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void describeTo(Description description) {
|
||||||
|
description.appendValue( "Hibernate#isInitialized == " + !assertInitialized );
|
||||||
|
}
|
||||||
|
}
|
@ -6,9 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.testing.orm.domain.gambit;
|
package org.hibernate.testing.orm.domain.gambit;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.Convert;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
@ -21,10 +25,25 @@
|
|||||||
@Entity
|
@Entity
|
||||||
public class EntityOfLists {
|
public class EntityOfLists {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
private List<String> listOfBasics;
|
private List<String> listOfBasics;
|
||||||
private List<Component> listOfComponents;
|
|
||||||
private List<EntityOfLists> listOfOneToMany;
|
private List<EnumValue> listOfConvertedEnums;
|
||||||
private List<EntityOfLists> listOfManyToMany;
|
private List<EnumValue> listOfEnums;
|
||||||
|
|
||||||
|
private List<SimpleComponent> listOfComponents;
|
||||||
|
|
||||||
|
private List<SimpleEntity> listOfOneToMany;
|
||||||
|
private List<SimpleEntity> listOfManyToMany;
|
||||||
|
|
||||||
|
public EntityOfLists() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityOfLists(Integer id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -35,6 +54,18 @@ public void setId(Integer id) {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// listOfBasics
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
@OrderColumn
|
@OrderColumn
|
||||||
public List<String> getListOfBasics() {
|
public List<String> getListOfBasics() {
|
||||||
@ -45,33 +76,117 @@ public void setListOfBasics(List<String> listOfBasics) {
|
|||||||
this.listOfBasics = listOfBasics;
|
this.listOfBasics = listOfBasics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addBasic(String basic) {
|
||||||
|
if ( listOfBasics == null ) {
|
||||||
|
listOfBasics = new ArrayList<>();
|
||||||
|
}
|
||||||
|
listOfBasics.add( basic );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// listOfConvertedEnums
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
@OrderColumn
|
@OrderColumn
|
||||||
public List<Component> getListOfComponents() {
|
@Convert(converter = EnumValueConverter.class)
|
||||||
|
public List<EnumValue> getListOfConvertedEnums() {
|
||||||
|
return listOfConvertedEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListOfConvertedEnums(List<EnumValue> listOfConvertedEnums) {
|
||||||
|
this.listOfConvertedEnums = listOfConvertedEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConvertedEnum(EnumValue value) {
|
||||||
|
if ( listOfConvertedEnums == null ) {
|
||||||
|
listOfConvertedEnums = new ArrayList<>();
|
||||||
|
}
|
||||||
|
listOfConvertedEnums.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// listOfEnums
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@OrderColumn
|
||||||
|
public List<EnumValue> getListOfEnums() {
|
||||||
|
return listOfEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListOfEnums(List<EnumValue> listOfEnums) {
|
||||||
|
this.listOfEnums = listOfEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEnum(EnumValue value) {
|
||||||
|
if ( listOfEnums == null ) {
|
||||||
|
listOfEnums = new ArrayList<>();
|
||||||
|
}
|
||||||
|
listOfEnums.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// listOfComponents
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@OrderColumn
|
||||||
|
public List<SimpleComponent> getListOfComponents() {
|
||||||
return listOfComponents;
|
return listOfComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListOfComponents(List<Component> listOfComponents) {
|
public void setListOfComponents(List<SimpleComponent> listOfComponents) {
|
||||||
this.listOfComponents = listOfComponents;
|
this.listOfComponents = listOfComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addComponent(SimpleComponent value) {
|
||||||
|
if ( listOfComponents == null ) {
|
||||||
|
listOfComponents = new ArrayList<>();
|
||||||
|
}
|
||||||
|
listOfComponents.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// listOfOneToMany
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
@OrderColumn
|
@OrderColumn
|
||||||
public List<EntityOfLists> getListOfOneToMany() {
|
public List<SimpleEntity> getListOfOneToMany() {
|
||||||
return listOfOneToMany;
|
return listOfOneToMany;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListOfOneToMany(List<EntityOfLists> listOfOneToMany) {
|
public void setListOfOneToMany(List<SimpleEntity> listOfOneToMany) {
|
||||||
this.listOfOneToMany = listOfOneToMany;
|
this.listOfOneToMany = listOfOneToMany;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addOneToMany(SimpleEntity value) {
|
||||||
|
if ( listOfOneToMany == null ) {
|
||||||
|
listOfOneToMany = new ArrayList<>();
|
||||||
|
}
|
||||||
|
listOfOneToMany.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// listOfManyToMany
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@OrderColumn
|
@OrderColumn
|
||||||
public List<EntityOfLists> getListOfManyToMany() {
|
public List<SimpleEntity> getListOfManyToMany() {
|
||||||
return listOfManyToMany;
|
return listOfManyToMany;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListOfManyToMany(List<EntityOfLists> listOfManyToMany) {
|
public void setListOfManyToMany(List<SimpleEntity> listOfManyToMany) {
|
||||||
this.listOfManyToMany = listOfManyToMany;
|
this.listOfManyToMany = listOfManyToMany;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addManyToMany(SimpleEntity value) {
|
||||||
|
if ( listOfManyToMany == null ) {
|
||||||
|
listOfManyToMany = new ArrayList<>();
|
||||||
|
}
|
||||||
|
listOfManyToMany.add( value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.testing.orm.domain.gambit;
|
package org.hibernate.testing.orm.domain.gambit;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.persistence.Convert;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
|
import javax.persistence.MapKeyEnumerated;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,11 +24,26 @@
|
|||||||
@Entity
|
@Entity
|
||||||
public class EntityOfMaps {
|
public class EntityOfMaps {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Map<String,String> basicToBasicMap;
|
private String name;
|
||||||
private Map<String, Component> basicToComponentMap;
|
|
||||||
private Map<Component,String> componentToBasicMap;
|
private Map<String,String> basicByBasic;
|
||||||
private Map<String, EntityOfMaps> basicToOneToMany;
|
private Map<EnumValue,String> basicByEnum;
|
||||||
private Map<String, EntityOfMaps> basicToManyToMany;
|
private Map<EnumValue,String> basicByConvertedEnum;
|
||||||
|
|
||||||
|
private Map<String, SimpleComponent> componentByBasic;
|
||||||
|
private Map<SimpleComponent,String> basicByComponent;
|
||||||
|
|
||||||
|
private Map<String, SimpleEntity> oneToManyByBasic;
|
||||||
|
private Map<SimpleEntity,String> basicByOneToMany;
|
||||||
|
private Map<String, SimpleEntity> manyToManyByBasic;
|
||||||
|
|
||||||
|
public EntityOfMaps() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityOfMaps(Integer id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -36,50 +54,175 @@ public void setId(Integer id) {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ElementCollection
|
public String getName() {
|
||||||
public Map<String, String> getBasicToBasicMap() {
|
return name;
|
||||||
return basicToBasicMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBasicToBasicMap(Map<String, String> basicToBasicMap) {
|
public void setName(String name) {
|
||||||
this.basicToBasicMap = basicToBasicMap;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// basicByBasic
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
public Map<String, Component> getBasicToComponentMap() {
|
public Map<String, String> getBasicByBasic() {
|
||||||
return basicToComponentMap;
|
return basicByBasic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBasicToComponentMap(Map<String, Component> basicToComponentMap) {
|
public void setBasicByBasic(Map<String, String> basicByBasic) {
|
||||||
this.basicToComponentMap = basicToComponentMap;
|
this.basicByBasic = basicByBasic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addBasicByBasic(String key, String val) {
|
||||||
|
if ( basicByBasic == null ) {
|
||||||
|
basicByBasic = new HashMap<>();
|
||||||
|
}
|
||||||
|
basicByBasic.put( key, val );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// basicByEnum
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
public Map<Component, String> getComponentToBasicMap() {
|
@MapKeyEnumerated
|
||||||
return componentToBasicMap;
|
public Map<EnumValue, String> getBasicByEnum() {
|
||||||
|
return basicByEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComponentToBasicMap(Map<Component, String> componentToBasicMap) {
|
public void setBasicByEnum(Map<EnumValue, String> basicByEnum) {
|
||||||
this.componentToBasicMap = componentToBasicMap;
|
this.basicByEnum = basicByEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addBasicByEnum(EnumValue key, String val) {
|
||||||
|
if ( basicByEnum == null ) {
|
||||||
|
basicByEnum = new HashMap<>();
|
||||||
|
}
|
||||||
|
basicByEnum.put( key, val );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// basicByConvertedEnum
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Convert(attributeName = "key", converter = EnumValueConverter.class)
|
||||||
|
public Map<EnumValue, String> getBasicByConvertedEnum() {
|
||||||
|
return basicByConvertedEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBasicByConvertedEnum(Map<EnumValue, String> basicByConvertedEnum) {
|
||||||
|
this.basicByConvertedEnum = basicByConvertedEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBasicByConvertedEnum(EnumValue key, String value) {
|
||||||
|
if ( basicByConvertedEnum == null ) {
|
||||||
|
basicByConvertedEnum = new HashMap<>();
|
||||||
|
}
|
||||||
|
basicByConvertedEnum.put( key, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// componentByBasic
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
public Map<String, SimpleComponent> getComponentByBasic() {
|
||||||
|
return componentByBasic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComponentByBasic(Map<String, SimpleComponent> componentByBasic) {
|
||||||
|
this.componentByBasic = componentByBasic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addComponentByBasic(String key, SimpleComponent value) {
|
||||||
|
if ( componentByBasic == null ) {
|
||||||
|
componentByBasic = new HashMap<>();
|
||||||
|
}
|
||||||
|
componentByBasic.put( key, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// basicByComponent
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
public Map<SimpleComponent, String> getBasicByComponent() {
|
||||||
|
return basicByComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBasicByComponent(Map<SimpleComponent, String> basicByComponent) {
|
||||||
|
this.basicByComponent = basicByComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBasicByComponent(SimpleComponent key, String value) {
|
||||||
|
if ( basicByComponent == null ) {
|
||||||
|
basicByComponent = new HashMap<>();
|
||||||
|
}
|
||||||
|
basicByComponent.put( key, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// oneToManyByBasic
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
@JoinColumn
|
@JoinColumn
|
||||||
public Map<String, EntityOfMaps> getBasicToOneToMany() {
|
public Map<String, SimpleEntity> getOneToManyByBasic() {
|
||||||
return basicToOneToMany;
|
return oneToManyByBasic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBasicToOneToMany(Map<String, EntityOfMaps> basicToOneToMany) {
|
public void setOneToManyByBasic(Map<String, SimpleEntity> oneToManyByBasic) {
|
||||||
this.basicToOneToMany = basicToOneToMany;
|
this.oneToManyByBasic = oneToManyByBasic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addOneToManyByComponent(String key, SimpleEntity value) {
|
||||||
|
if ( oneToManyByBasic == null ) {
|
||||||
|
oneToManyByBasic = new HashMap<>();
|
||||||
|
}
|
||||||
|
oneToManyByBasic.put( key, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// basicByOneToMany
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
public Map<SimpleEntity, String> getBasicByOneToMany() {
|
||||||
|
return basicByOneToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBasicByOneToMany(Map<SimpleEntity, String> basicByOneToMany) {
|
||||||
|
this.basicByOneToMany = basicByOneToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOneToManyByBasic(SimpleEntity key, String val) {
|
||||||
|
if ( basicByOneToMany == null ) {
|
||||||
|
basicByOneToMany = new HashMap<>();
|
||||||
|
}
|
||||||
|
basicByOneToMany.put( key, val );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// manyToManyByBasic
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
public Map<String, EntityOfMaps> getBasicToManyToMany() {
|
public Map<String, SimpleEntity> getManyToManyByBasic() {
|
||||||
return basicToManyToMany;
|
return manyToManyByBasic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBasicToManyToMany(Map<String, EntityOfMaps> basicToManyToMany) {
|
public void setManyToManyByBasic(Map<String, SimpleEntity> manyToManyByBasic) {
|
||||||
this.basicToManyToMany = basicToManyToMany;
|
this.manyToManyByBasic = manyToManyByBasic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addManyToManyByComponent(String key, SimpleEntity value) {
|
||||||
|
if ( manyToManyByBasic == null ) {
|
||||||
|
manyToManyByBasic = new HashMap<>();
|
||||||
|
}
|
||||||
|
manyToManyByBasic.put( key, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,17 @@
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
import javax.persistence.CollectionTable;
|
import javax.persistence.CollectionTable;
|
||||||
|
import javax.persistence.Convert;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.annotations.LazyCollection;
|
import org.hibernate.annotations.LazyCollection;
|
||||||
import org.hibernate.annotations.LazyCollectionOption;
|
import org.hibernate.annotations.LazyCollectionOption;
|
||||||
@ -25,25 +30,29 @@
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Entity
|
@Entity
|
||||||
|
@Table(name = "entity_containing_sets")
|
||||||
public class EntityOfSets {
|
public class EntityOfSets {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Set<String> setOfBasics;
|
private String name;
|
||||||
private Set<Component> setOfComponents;
|
|
||||||
private Set<Component> setOfExtraLazyComponents;
|
|
||||||
private Set<EntityOfSets> setOfOneToMany;
|
|
||||||
private Set<EntityOfSets> setOfManyToMany;
|
|
||||||
|
|
||||||
|
private Set<String> setOfBasics;
|
||||||
private SortedSet<String> sortedSetOfBasics;
|
private SortedSet<String> sortedSetOfBasics;
|
||||||
|
|
||||||
|
private Set<EnumValue> setOfEnums;
|
||||||
|
private Set<EnumValue> setOfConvertedEnums;
|
||||||
|
|
||||||
|
private Set<SimpleComponent> setOfComponents;
|
||||||
|
private Set<SimpleComponent> extraLazySetOfComponents;
|
||||||
|
|
||||||
|
private Set<SimpleEntity> setOfOneToMany;
|
||||||
|
private Set<SimpleEntity> setOfManyToMany;
|
||||||
|
|
||||||
public EntityOfSets() {
|
public EntityOfSets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityOfSets(Integer id) {
|
public EntityOfSets(Integer id, String name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.setOfBasics = new HashSet<>();
|
this.name = name;
|
||||||
this.setOfComponents = new HashSet<>();
|
|
||||||
this.setOfOneToMany = new HashSet<>();
|
|
||||||
this.setOfManyToMany = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@ -55,8 +64,19 @@ public void setId(Integer id) {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// setOfBasics
|
||||||
|
|
||||||
@ElementCollection()
|
@ElementCollection()
|
||||||
// @ElementCollection( fetch = FetchType.EAGER )
|
|
||||||
@CollectionTable( name = "EntityOfSet_basics")
|
@CollectionTable( name = "EntityOfSet_basics")
|
||||||
public Set<String> getSetOfBasics() {
|
public Set<String> getSetOfBasics() {
|
||||||
return setOfBasics;
|
return setOfBasics;
|
||||||
@ -66,46 +86,16 @@ public void setSetOfBasics(Set<String> setOfBasics) {
|
|||||||
this.setOfBasics = setOfBasics;
|
this.setOfBasics = setOfBasics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ElementCollection
|
public void addBasic(String value) {
|
||||||
@CollectionTable( name = "EntityOfSet_components")
|
if ( setOfBasics == null ) {
|
||||||
public Set<Component> getSetOfComponents() {
|
setOfBasics = new HashSet<>();
|
||||||
return setOfComponents;
|
}
|
||||||
|
setOfBasics.add( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSetOfComponents(Set<Component> setOfComponents) {
|
|
||||||
this.setOfComponents = setOfComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@LazyCollection( LazyCollectionOption.EXTRA )
|
// sortedSetOfBasics
|
||||||
@CollectionTable( name = "EntityOfSet_extraLazyComponents")
|
|
||||||
public Set<Component> getSetOfExtraLazyComponents() {
|
|
||||||
return setOfExtraLazyComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfExtraLazyComponents(Set<Component> setOfExtraLazyComponents) {
|
|
||||||
this.setOfExtraLazyComponents = setOfExtraLazyComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany
|
|
||||||
@CollectionTable( name = "EntityOfSet_oneToMany")
|
|
||||||
public Set<EntityOfSets> getSetOfOneToMany() {
|
|
||||||
return setOfOneToMany;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfOneToMany(Set<EntityOfSets> setOfOneToMany) {
|
|
||||||
this.setOfOneToMany = setOfOneToMany;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToMany
|
|
||||||
@CollectionTable( name = "EntityOfSet_manyToMany")
|
|
||||||
public Set<EntityOfSets> getSetOfManyToMany() {
|
|
||||||
return setOfManyToMany;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetOfManyToMany(Set<EntityOfSets> setOfManyToMany) {
|
|
||||||
this.setOfManyToMany = setOfManyToMany;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ElementCollection()
|
@ElementCollection()
|
||||||
@CollectionTable( name = "EntityOfSet_sortedBasics")
|
@CollectionTable( name = "EntityOfSet_sortedBasics")
|
||||||
@ -117,4 +107,138 @@ public SortedSet<String> getSortedSetOfBasics() {
|
|||||||
public void setSortedSetOfBasics(SortedSet<String> sortedSetOfBasics) {
|
public void setSortedSetOfBasics(SortedSet<String> sortedSetOfBasics) {
|
||||||
this.sortedSetOfBasics = sortedSetOfBasics;
|
this.sortedSetOfBasics = sortedSetOfBasics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addSortedBasic(String value) {
|
||||||
|
if ( sortedSetOfBasics == null ) {
|
||||||
|
sortedSetOfBasics = new TreeSet<>();
|
||||||
|
}
|
||||||
|
sortedSetOfBasics.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// setOfConvertedEnums
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Convert(converter = EnumValueConverter.class)
|
||||||
|
public Set<EnumValue> getSetOfConvertedEnums() {
|
||||||
|
return setOfConvertedEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetOfConvertedEnums(Set<EnumValue> setOfConvertedEnums) {
|
||||||
|
this.setOfConvertedEnums = setOfConvertedEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConvertedEnum(EnumValue value) {
|
||||||
|
if ( setOfConvertedEnums == null ) {
|
||||||
|
setOfConvertedEnums = new HashSet<>();
|
||||||
|
}
|
||||||
|
setOfConvertedEnums.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// setOfEnums
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
public Set<EnumValue> getSetOfEnums() {
|
||||||
|
return setOfEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetOfEnums(Set<EnumValue> setOfEnums) {
|
||||||
|
this.setOfEnums = setOfEnums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEnum(EnumValue value) {
|
||||||
|
if ( setOfEnums == null ) {
|
||||||
|
setOfEnums = new HashSet<>();
|
||||||
|
}
|
||||||
|
setOfEnums.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// setOfComponents
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable( name = "EntityOfSet_components")
|
||||||
|
public Set<SimpleComponent> getSetOfComponents() {
|
||||||
|
return setOfComponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetOfComponents(Set<SimpleComponent> setOfComponents) {
|
||||||
|
this.setOfComponents = setOfComponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addComponent(SimpleComponent value) {
|
||||||
|
if ( setOfComponents == null ) {
|
||||||
|
setOfComponents = new HashSet<>();
|
||||||
|
}
|
||||||
|
setOfComponents.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// setOfExtraLazyComponents
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@LazyCollection( LazyCollectionOption.EXTRA )
|
||||||
|
@CollectionTable( name = "EntityOfSet_extraLazyComponents")
|
||||||
|
public Set<SimpleComponent> getExtraLazySetOfComponents() {
|
||||||
|
return extraLazySetOfComponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraLazySetOfComponents(Set<SimpleComponent> extraLazySetOfComponents) {
|
||||||
|
this.extraLazySetOfComponents = extraLazySetOfComponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addExtraLazyComponent(SimpleComponent value) {
|
||||||
|
if ( extraLazySetOfComponents == null ) {
|
||||||
|
extraLazySetOfComponents = new HashSet<>();
|
||||||
|
}
|
||||||
|
extraLazySetOfComponents.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// setOfOneToMany
|
||||||
|
|
||||||
|
@OneToMany
|
||||||
|
@CollectionTable( name = "EntityOfSet_oneToMany")
|
||||||
|
public Set<SimpleEntity> getSetOfOneToMany() {
|
||||||
|
return setOfOneToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetOfOneToMany(Set<SimpleEntity> setOfOneToMany) {
|
||||||
|
this.setOfOneToMany = setOfOneToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOneToMany(SimpleEntity value) {
|
||||||
|
if ( setOfOneToMany == null ) {
|
||||||
|
setOfOneToMany = new HashSet<>();
|
||||||
|
}
|
||||||
|
setOfOneToMany.add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// setOfManyToMany
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
@CollectionTable( name = "EntityOfSet_manyToMany")
|
||||||
|
public Set<SimpleEntity> getSetOfManyToMany() {
|
||||||
|
return setOfManyToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetOfManyToMany(Set<SimpleEntity> setOfManyToMany) {
|
||||||
|
this.setOfManyToMany = setOfManyToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addManyToMany(SimpleEntity value) {
|
||||||
|
if ( setOfManyToMany == null ) {
|
||||||
|
setOfManyToMany = new HashSet<>();
|
||||||
|
}
|
||||||
|
setOfManyToMany.add( value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.metamodel.mapping.collections;
|
package org.hibernate.testing.orm.domain.gambit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
@ -4,7 +4,7 @@
|
|||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.metamodel.mapping.collections;
|
package org.hibernate.testing.orm.domain.gambit;
|
||||||
|
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
|
|
@ -4,7 +4,7 @@
|
|||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.metamodel.mapping.collections;
|
package org.hibernate.testing.orm.domain.gambit;
|
||||||
|
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
|
|
||||||
@ -12,14 +12,14 @@
|
|||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public class SomeStuff {
|
public class SimpleComponent {
|
||||||
private String anAttribute;
|
private String anAttribute;
|
||||||
private String anotherAttribute;
|
private String anotherAttribute;
|
||||||
|
|
||||||
public SomeStuff() {
|
public SimpleComponent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SomeStuff(String anAttribute, String anotherAttribute) {
|
public SimpleComponent(String anAttribute, String anotherAttribute) {
|
||||||
this.anAttribute = anAttribute;
|
this.anAttribute = anAttribute;
|
||||||
this.anotherAttribute = anotherAttribute;
|
this.anotherAttribute = anotherAttribute;
|
||||||
}
|
}
|
@ -34,6 +34,13 @@ public class SimpleEntity {
|
|||||||
public SimpleEntity() {
|
public SimpleEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SimpleEntity(
|
||||||
|
Integer id,
|
||||||
|
String someString) {
|
||||||
|
this.id = id;
|
||||||
|
this.someString = someString;
|
||||||
|
}
|
||||||
|
|
||||||
public SimpleEntity(
|
public SimpleEntity(
|
||||||
Integer id,
|
Integer id,
|
||||||
Date someDate,
|
Date someDate,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user