diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbySqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbySqlAstTranslator.java index 5f886c46b51b..ffecb10b56d2 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbySqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbySqlAstTranslator.java @@ -244,8 +244,7 @@ protected void renderPartitionItem(Expression expression) { if ( expression instanceof Literal ) { appendSql( "'0'" ); } - else if ( expression instanceof Summarization ) { - Summarization summarization = (Summarization) expression; + else if ( expression instanceof Summarization summarization ) { appendSql( summarization.getKind().sqlText() ); appendSql( OPEN_PARENTHESIS ); renderCommaSeparated( summarization.getGroupings() ); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index 33ba7a271fff..a74dcb2ac4d0 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -106,7 +106,6 @@ import static org.hibernate.internal.util.JdbcExceptionHelper.extractErrorCode; import static org.hibernate.query.sqm.produce.function.FunctionParameterType.STRING; import static org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers.impliedOrInvariant; -import static org.hibernate.type.SqlTypes.BIGINT; import static org.hibernate.type.SqlTypes.BINARY; import static org.hibernate.type.SqlTypes.FLOAT; import static org.hibernate.type.SqlTypes.LONG32NVARCHAR; @@ -214,8 +213,8 @@ protected String columnType(int sqlTypeCode) { switch ( sqlTypeCode ) { case TINYINT: return "smallint"; - case BIGINT: - return "int8"; +// case BIGINT: +// return "int8"; case TIME: return "datetime hour to second"; case TIMESTAMP: @@ -252,7 +251,7 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR ); ddlTypeRegistry.addDescriptor( - CapacityDependentDdlType.builder( VARCHAR, columnType( LONG32VARCHAR ), "varchar(255)",this ) + CapacityDependentDdlType.builder( VARCHAR, columnType( LONG32VARCHAR ), "lvarchar",this ) .withTypeCapacity( 255, "varchar($l)" ) .withTypeCapacity( getMaxVarcharLength(), columnType( VARCHAR ) ) .build() @@ -340,6 +339,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio functionFactory.initcap(); functionFactory.yearMonthDay(); functionFactory.ceiling_ceil(); + functionFactory.concat_pipeOperator(); functionFactory.ascii(); functionFactory.char_chr(); functionFactory.addMonths(); @@ -355,14 +355,6 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio functionRegistry.registerAlternateKey( "var_samp", "variance" ); - // the pipe operator or concat() function returns strings with trailing whitespace - functionRegistry.patternDescriptorBuilder( "concat", "cast(?1||?2... as varchar(255))" ) - .setInvariantType( stringBasicType ) - .setMinArgumentCount( 1 ) - .setArgumentTypeResolver( impliedOrInvariant( typeConfiguration, STRING ) ) - .setArgumentListSignature( "(STRING string0[, STRING string1[, ...]])" ) - .register(); - if ( getVersion().isSameOrAfter( 12 ) ) { functionFactory.locate_charindex(); } @@ -443,6 +435,8 @@ public String extractPattern(TemporalUnit unit) { case HOUR -> "to_number(to_char(?2,'%H'))"; case DAY_OF_WEEK -> "(weekday(?2)+1)"; case DAY_OF_MONTH -> "day(?2)"; + case EPOCH -> "(to_number(cast(cast(sum(?2-datetime(1970-1-1) year to day) as interval day(9) to day) as varchar(12)))*86400+to_number(cast(cast(sum(cast(?2 as datetime hour to second)-datetime(00:00:00) hour to second) as interval second(6) to second) as varchar(9))))"; + case NATIVE -> "((to_number(cast(cast(sum(?2) as interval day(9) to day) as varchar(12)))*86400+mod(to_number(cast(cast(sum(?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?2) as interval fraction to fraction) as varchar(6))))*1e3)"; default -> "?1(?2)"; }; } @@ -591,26 +585,35 @@ public boolean supportsValuesListForInsert() { @Override public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() { - return (sqlException, message, sql) -> - switch ( extractErrorCode( sqlException ) ) { - case -378, -233, -107, -113, -134, -143, -144, -154 -> - //TODO: which of these are these are really LockTimeoutExceptions - // rather than the more generic LockAcquisitionException? - new LockAcquisitionException( message, sqlException, sql ); - case -239, -268 -> - new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.UNIQUE, - getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) ); - case -691, -692 -> - new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.FOREIGN_KEY, - getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) ); - case -703, -391 -> - new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.NOT_NULL, - getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) ); - case -530 -> - new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.CHECK, - getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) ); - default -> null; - }; + return (exception, message, sql) -> switch ( extractErrorCode( exception ) ) { + case -239, -268 -> + new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.UNIQUE, + getViolatedConstraintNameExtractor().extractConstraintName( exception ) ); + case -691, -692 -> + new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.FOREIGN_KEY, + getViolatedConstraintNameExtractor().extractConstraintName( exception ) ); + case -703, -391 -> + new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.NOT_NULL, + getViolatedConstraintNameExtractor().extractConstraintName( exception ) ); + case -530 -> + new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.CHECK, + getViolatedConstraintNameExtractor().extractConstraintName( exception ) ); + default -> { + // unwrap the ISAM error, if any + if ( exception.getCause() instanceof SQLException cause && cause != exception ) { + yield switch ( extractErrorCode( cause ) ) { + case -107, -113, -134, -143, -144, -154 -> + //TODO: which of these are these are really LockTimeoutExceptions + // rather than the more generic LockAcquisitionException? + new LockAcquisitionException( message, exception, sql ); + default -> null; + }; + } + else { + yield null; + } + } + }; } @Override @@ -735,6 +738,9 @@ public String castPattern(CastType from, CastType to) { return "case ?1 when 't' then 1 when 'f' then 0 else null end"; } } + if ( from == CastType.STRING && to == CastType.BOOLEAN ) { + return buildStringToBooleanCast( "'t'", "'f'" ); + } return super.castPattern( from, to ); } @@ -977,14 +983,13 @@ public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType @Override public String getSelectClauseNullString(int sqlType, TypeConfiguration typeConfiguration) { final DdlType descriptor = typeConfiguration.getDdlTypeRegistry().getDescriptor( sqlType ); - if ( descriptor == null ) { - // just cast it to an arbitrary SQL type, - // which we expect to be ignored by higher layers - return "null::int"; - } - else { - return "null::" + castType( descriptor ); - } + final String castType = + descriptor != null + ? castType( descriptor ) + // just cast it to an arbitrary SQL type, + // which we expect to be ignored by higher layers + : "integer"; + return "cast(null as " + castType + ")"; } private static String castType(DdlType descriptor) { diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java index 1e8f701a8376..997b67afa479 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java @@ -7,16 +7,25 @@ import java.util.List; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.query.IllegalQueryOperationException; import org.hibernate.query.sqm.ComparisonOperator; +import org.hibernate.query.sqm.sql.internal.SqmParameterInterpretation; import org.hibernate.sql.ast.Clause; -import org.hibernate.sql.ast.SqlAstNodeRenderingMode; -import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator; +import org.hibernate.sql.ast.spi.SqlAstTranslatorWithMerge; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.Statement; +import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression; +import org.hibernate.sql.ast.tree.expression.CaseSimpleExpression; import org.hibernate.sql.ast.tree.expression.Expression; +import org.hibernate.sql.ast.tree.expression.FunctionExpression; import org.hibernate.sql.ast.tree.expression.Literal; +import org.hibernate.sql.ast.tree.expression.SelfRenderingExpression; import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.sql.ast.tree.expression.Summarization; +import org.hibernate.sql.ast.tree.from.ValuesTableReference; +import org.hibernate.sql.ast.tree.insert.ConflictClause; +import org.hibernate.sql.ast.tree.insert.InsertSelectStatement; +import org.hibernate.sql.ast.tree.select.QueryGroup; import org.hibernate.sql.ast.tree.select.QueryPart; import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.ast.tree.select.SelectClause; @@ -28,12 +37,28 @@ * * @author Christian Beikov */ -public class InformixSqlAstTranslator extends AbstractSqlAstTranslator { +public class InformixSqlAstTranslator extends SqlAstTranslatorWithMerge { public InformixSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement) { super( sessionFactory, statement ); } + @Override + protected void visitQueryClauses(QuerySpec querySpec) { + visitSelectClause( querySpec.getSelectClause() ); + visitFromClause( querySpec.getFromClause() ); + if ( !hasFrom( querySpec.getFromClause() ) + && hasWhere( querySpec.getWhereClauseRestrictions() ) ) { + append( " from " ); + append( getDual() ); + } + visitWhereClause( querySpec.getWhereClauseRestrictions() ); + visitGroupByClause( querySpec, getDialect().getGroupBySelectItemReferenceStrategy() ); + visitHavingClause( querySpec ); + visitOrderBy( querySpec.getSortSpecifications() ); + visitOffsetFetchClause( querySpec ); + } + @Override public void visitSelectClause(SelectClause selectClause) { getClauseStack().push( Clause.SELECT ); @@ -49,13 +74,21 @@ public void visitSelectClause(SelectClause selectClause) { } + @Override + protected void renderSelectExpression(Expression expression) { + renderSelectExpressionWithCastedOrInlinedPlainParameters( expression ); + } + @Override protected void visitSqlSelections(SelectClause selectClause) { - if ( supportsSkipFirstClause() ) { - renderSkipFirstClause( (QuerySpec) getQueryPartStack().getCurrent() ); - } - else { - renderFirstClause( (QuerySpec) getQueryPartStack().getCurrent() ); + final QuerySpec querySpec = (QuerySpec) getQueryPartStack().getCurrent(); + if ( isRowsOnlyFetchClauseType( querySpec ) ) { + if ( supportsSkipFirstClause() ) { + renderSkipFirstClause( querySpec ); + } + else { + renderFirstClause( querySpec ); + } } if ( selectClause.isDistinct() ) { appendSql( "distinct " ); @@ -136,17 +169,17 @@ else if ( expression instanceof Summarization ) { } } - @Override - protected void renderNull(Literal literal) { - if ( getParameterRenderingMode() == SqlAstNodeRenderingMode.NO_UNTYPED ) { - renderCasted( literal ); - } - else { - int sqlType = literal.getExpressionType().getSingleJdbcMapping().getJdbcType().getJdbcTypeCode(); - String nullString = getDialect().getSelectClauseNullString( sqlType, getSessionFactory().getTypeConfiguration() ); - appendSql( nullString ); - } - } +// @Override +// protected void renderNull(Literal literal) { +// if ( getParameterRenderingMode() == SqlAstNodeRenderingMode.NO_UNTYPED ) { +// renderCasted( literal ); +// } +// else { +// int sqlType = literal.getExpressionType().getSingleJdbcMapping().getJdbcType().getJdbcTypeCode(); +// String nullString = getDialect().getSelectClauseNullString( sqlType, getSessionFactory().getTypeConfiguration() ); +// appendSql( nullString ); +// } +// } @Override protected void renderInsertIntoNoColumns(TableInsertStandard tableInsert) { @@ -161,4 +194,124 @@ private boolean supportsParameterOffsetFetchExpression() { private boolean supportsSkipFirstClause() { return getDialect().getVersion().isSameOrAfter( 11 ); } + + @Override + protected void visitConflictClause(ConflictClause conflictClause) { + if ( conflictClause != null ) { + if ( conflictClause.isDoUpdate() && conflictClause.getConstraintName() != null ) { + throw new IllegalQueryOperationException( "Insert conflict 'do update' clause with constraint name is not supported" ); + } + } + } + + @Override + protected void visitInsertStatementOnly(InsertSelectStatement statement) { + if ( statement.getConflictClause() == null || statement.getConflictClause().isDoNothing() ) { + // Render plain insert statement and possibly run into unique constraint violation + super.visitInsertStatementOnly( statement ); + } + else { + visitInsertStatementEmulateMerge( statement ); + } + } + + @Override + public void visitValuesTableReference(ValuesTableReference tableReference) { + emulateValuesTableReferenceColumnAliasing( tableReference ); + } + + protected boolean shouldEmulateFetchClause(QueryPart queryPart) { + // Check if current query part is already row numbering to avoid infinite recursion + return useOffsetFetchClause( queryPart ) && getQueryPartForRowNumbering() != queryPart + && getDialect().supportsWindowFunctions() && !isRowsOnlyFetchClauseType( queryPart ); + } + + @Override + public void visitQueryGroup(QueryGroup queryGroup) { + if ( shouldEmulateFetchClause( queryGroup ) ) { + emulateFetchOffsetWithWindowFunctions( queryGroup, true ); + } + else { + super.visitQueryGroup( queryGroup ); + } + } + + @Override + public void visitQuerySpec(QuerySpec querySpec) { + if ( shouldEmulateFetchClause( querySpec ) ) { + emulateFetchOffsetWithWindowFunctions( querySpec, true ); + } + else { + super.visitQuerySpec( querySpec ); + } + } + + @Override + protected void visitArithmeticOperand(Expression expression) { + if ( expression instanceof SqmParameterInterpretation + && expression.getExpressionType() != null + && expression.getExpressionType().getJdbcTypeCount() == 1 ) { + final String castType = + switch ( expression.getExpressionType().getSingleJdbcMapping().getCastType() ) { + case FLOAT, DOUBLE -> "float" ; + case INTEGER -> "integer" ; + case LONG -> "bigint"; + default -> null; + }; + if ( castType != null ) { + append( "cast(" ); + } + super.visitArithmeticOperand( expression ); + if ( castType != null ) { + append( " as " ); + append( castType ); + append( ")" ); + } + } + else { + super.visitArithmeticOperand( expression ); + } + } + + @Override + public void visitSelfRenderingExpression(SelfRenderingExpression expression) { + final boolean isStringFunctionWithParameterArg = + expression instanceof FunctionExpression fn + && expression.getExpressionType() != null + && expression.getExpressionType().getJdbcTypeCount() == 1 + && expression.getExpressionType().getSingleJdbcMapping().getJdbcType().isString() + && fn.getArguments().stream().anyMatch( arg -> arg instanceof SqmParameterInterpretation ); + if ( isStringFunctionWithParameterArg ) { + append( "cast(" ); + } + super.visitSelfRenderingExpression( expression ); + if ( isStringFunctionWithParameterArg ) { + append( " as lvarchar)" ); + } + } + + private void caseArgument(Expression expression) { + // concatenation inside a case must be cast to varchar(255) + // or we get a bunch of trailing whitespace + final boolean concat = + expression instanceof FunctionExpression fn + && fn.getFunctionName().equals( "concat" ); + if ( concat ) { + append( "cast(" ); + } + expression.accept( this ); + if ( concat ) { + append( " as varchar(255))"); + } + } + + @Override + protected void visitCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression, boolean inSelect) { + visitAnsiCaseSearchedExpression( caseSearchedExpression, this::caseArgument ); + } + + @Override + protected void visitCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression, boolean inSelect) { + visitAnsiCaseSimpleExpression( caseSimpleExpression, this::caseArgument ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastFunction.java index cb0dde411195..a0471b4fa516 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastFunction.java @@ -77,6 +77,9 @@ public void render( renderCastArrayToString( sqlAppender, arguments.get( 0 ), dialect, walker ); } else { + if ( source instanceof QueryLiteral literal && literal.getLiteralValue() == null ) { + literal.setInCast(true); + } new PatternRenderer( dialect.castPattern( sourceType, targetType ) ) .render( sqlAppender, arguments, walker ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2SqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2SqlAstTranslator.java index eb9a8fb28502..6bf6bdf0d8cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2SqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2SqlAstTranslator.java @@ -304,11 +304,14 @@ protected void emulateFetchOffsetWithWindowFunctionsVisitQueryPart(QueryPart que } } + private boolean shouldEmulateFetch(QueryPart queryPart) { + return shouldEmulateFetchClause( queryPart ) + || getQueryPartForRowNumbering() != queryPart && !supportsOffsetClause() && hasOffset( queryPart ); + } + @Override public void visitQueryGroup(QueryGroup queryGroup) { - final boolean emulateFetchClause = shouldEmulateFetchClause( queryGroup ); - if ( emulateFetchClause || - getQueryPartForRowNumbering() != queryGroup && !supportsOffsetClause() && hasOffset( queryGroup ) ) { + if ( shouldEmulateFetch( queryGroup ) ) { emulateFetchOffsetWithWindowFunctions( queryGroup, true ); } else { @@ -318,9 +321,7 @@ public void visitQueryGroup(QueryGroup queryGroup) { @Override public void visitQuerySpec(QuerySpec querySpec) { - final boolean emulateFetchClause = shouldEmulateFetchClause( querySpec ); - if ( emulateFetchClause || - getQueryPartForRowNumbering() != querySpec && !supportsOffsetClause() && hasOffset( querySpec ) ) { + if ( shouldEmulateFetch( querySpec ) ) { emulateFetchOffsetWithWindowFunctions( querySpec, true ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/MutationStatementPreparerImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/MutationStatementPreparerImpl.java index 8eb94499827c..59c8837ccf0d 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/MutationStatementPreparerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/MutationStatementPreparerImpl.java @@ -109,7 +109,7 @@ public PreparedStatement prepareStatement() { return preparedStatement; } catch (SQLException e) { - throw sqlExceptionHelper().convert( e, "could not prepare statement", sql ); + throw sqlExceptionHelper().convert( e, "Could not prepare statement", sql ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java index 69ead6ffe0c0..83f5e472b281 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java @@ -193,7 +193,7 @@ public PreparedStatement prepareStatement() { return preparedStatement; } catch ( SQLException e ) { - throw sqlExceptionHelper().convert( e, "could not prepare statement", sql ); + throw sqlExceptionHelper().convert( e, "Could not prepare statement", sql ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index 61d406ac2f2d..cf6d405b49d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -3631,13 +3631,8 @@ else if ( !dialect.supportsDuplicateSelectItemsInQueryGroup() ) { if ( queryGroupAlias != null ) { appendSql( OPEN_PARENTHESIS ); } - visitSelectClause( querySpec.getSelectClause() ); - visitFromClause( querySpec.getFromClause() ); - visitWhereClause( querySpec.getWhereClauseRestrictions() ); - visitGroupByClause( querySpec, dialect.getGroupBySelectItemReferenceStrategy() ); - visitHavingClause( querySpec ); - visitOrderBy( querySpec.getSortSpecifications() ); - visitOffsetFetchClause( querySpec ); + + visitQueryClauses( querySpec ); // We render the FOR UPDATE clause in the parent query if ( queryPartForRowNumbering == null ) { visitForUpdateClause( querySpec ); @@ -3660,6 +3655,16 @@ else if ( !dialect.supportsDuplicateSelectItemsInQueryGroup() ) { } } + protected void visitQueryClauses(QuerySpec querySpec) { + visitSelectClause( querySpec.getSelectClause() ); + visitFromClause( querySpec.getFromClause() ); + visitWhereClause( querySpec.getWhereClauseRestrictions() ); + visitGroupByClause( querySpec, dialect.getGroupBySelectItemReferenceStrategy() ); + visitHavingClause( querySpec ); + visitOrderBy( querySpec.getSortSpecifications() ); + visitOffsetFetchClause( querySpec ); + } + private boolean hasDuplicateSelectItems(QuerySpec querySpec) { final List sqlSelections = querySpec.getSelectClause().getSqlSelections(); final Map map = new IdentityHashMap<>( sqlSelections.size() ); @@ -3672,9 +3677,8 @@ private boolean hasDuplicateSelectItems(QuerySpec querySpec) { } protected final void visitWhereClause(Predicate whereClauseRestrictions) { - final Predicate additionalWherePredicate = this.additionalWherePredicate; - if ( whereClauseRestrictions != null && !whereClauseRestrictions.isEmpty() - || additionalWherePredicate != null ) { + if ( hasWhere( whereClauseRestrictions ) ) { + final Predicate additionalWherePredicate = this.additionalWherePredicate; appendSql( " where " ); clauseStack.push( Clause.WHERE ); @@ -3698,6 +3702,11 @@ else if ( additionalWherePredicate != null ) { } } + protected boolean hasWhere(Predicate whereClauseRestrictions) { + return whereClauseRestrictions != null && !whereClauseRestrictions.isEmpty() + || additionalWherePredicate != null; + } + protected Expression resolveAliasedExpression(Expression expression) { // This can happen when using window functions for emulating the offset/fetch clause of a query group // But in that case we always use a SqlSelectionExpression anyway, so this is fine as it doesn't need resolving @@ -5611,7 +5620,7 @@ protected void renderSelectExpression(Expression expression) { } protected void renderExpressionAsClauseItem(Expression expression) { - // Most databases do not support predicates as top level items + // Most databases do not support predicates as top-level items if ( expression instanceof Predicate ) { appendSql( "case when " ); expression.accept( this ); @@ -5627,7 +5636,7 @@ protected void renderExpressionAsClauseItem(Expression expression) { } protected void renderSelectExpressionWithCastedOrInlinedPlainParameters(Expression expression) { - // Null literals have to be casted in the select clause + // Null literals have to be cast in the select clause if ( expression instanceof Literal literal ) { if ( literal.getLiteralValue() == null ) { renderCasted( literal ); @@ -5690,8 +5699,9 @@ protected void renderLiteral(Literal literal, boolean castParameter) { // If we encounter a plain literal in the select clause which has no literal formatter, we must render it as parameter if ( literalFormatter == null ) { parameterBinders.add( literal ); - final String marker = parameterMarkerStrategy.createMarker( parameterBinders.size(), literal.getJdbcMapping().getJdbcType() ); - final LiteralAsParameter jdbcParameter = new LiteralAsParameter<>( literal, marker ); + final JdbcType jdbcType = literal.getJdbcMapping().getJdbcType(); + final String marker = parameterMarkerStrategy.createMarker( parameterBinders.size(), jdbcType ); + final LiteralAsParameter jdbcParameter = new LiteralAsParameter<>( literal, marker ); if ( castParameter ) { renderCasted( jdbcParameter ); } @@ -5715,13 +5725,17 @@ protected void renderLiteral(Literal literal, boolean castParameter) { @Override public void visitFromClause(FromClause fromClause) { - if ( fromClause == null || fromClause.getRoots().isEmpty() ) { - appendSql( getFromDualForSelectOnly() ); - } - else { + if ( hasFrom( fromClause ) ) { appendSql( " from " ); renderFromClauseSpaces( fromClause ); } + else { + appendSql( getFromDualForSelectOnly() ); + } + } + + protected boolean hasFrom(FromClause fromClause) { + return fromClause != null && !fromClause.getRoots().isEmpty(); } protected void renderFromClauseSpaces(FromClause fromClause) { @@ -7439,7 +7453,12 @@ public void visitJdbcLiteral(JdbcLiteral jdbcLiteral) { @Override public void visitQueryLiteral(QueryLiteral queryLiteral) { - visitLiteral( queryLiteral ); + if ( queryLiteral.getLiteralValue() == null && queryLiteral.isInCast() ) { + appendSql( SqlAppender.NULL_KEYWORD ); + } + else { + visitLiteral( queryLiteral ); + } } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java index 9cef9ff1feda..b8958b373dc5 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java @@ -30,6 +30,7 @@ public class QueryLiteral implements Literal, DomainResultProducer { private final T value; private final SqlExpressible expressible; + private boolean inCast; public QueryLiteral(T value, SqlExpressible expressible) { assert value == null || expressible.getJdbcMapping().getJdbcJavaType().isInstance( value ); @@ -100,4 +101,12 @@ public void applySqlSelections(DomainResultCreationState creationState) { creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } + + public void setInCast(boolean inCast) { + this.inCast = inCast; + } + + public boolean isInCast() { + return inCast; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java index 99e1ada251fb..eb5c4648398c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java @@ -135,8 +135,8 @@ public DdlType getDescriptor(int sqlTypeCode) { } /** - * Get the SQL type name for the specified {@link java.sql.Types JDBC type code}, - * filling in the placemarkers {@code $l}, {@code $p}, and {@code $s} + * Get the SQL type name for the specified {@linkplain java.sql.Types JDBC + * type code}, filling in the placemarkers {@code $l}, {@code $p}, and {@code $s} * with the default length, precision, and scale for the given SQL dialect. * * @param typeCode the JDBC type code diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/manytoonewithformula/ManyToOneWithFormulaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/manytoonewithformula/ManyToOneWithFormulaTest.java index 519ae2c9a9d5..8071f6bb6c92 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/manytoonewithformula/ManyToOneWithFormulaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/manytoonewithformula/ManyToOneWithFormulaTest.java @@ -150,7 +150,7 @@ public void testReferencedColumnNameBelongsToEmbeddedIdOfReferencedEntity(Sessio @SessionFactory @SkipForDialect( dialectClass = HSQLDialect.class, reason = "The used join conditions does not work in HSQLDB. See HHH-4497." ) @SkipForDialect( dialectClass = OracleDialect.class, reason = "Oracle do not support 'substring' function JDBC escape" ) - @SkipForDialect( dialectClass = InformixDialect.class, reason = "Oracle do not support 'substring' function JDBC escape" ) + @SkipForDialect( dialectClass = InformixDialect.class, reason = "Informix does not support 'substring' function JDBC escape" ) @SkipForDialect( dialectClass = AltibaseDialect.class, reason = " Altibase char type returns with trailing spaces") public void testManyToOneFromNonPkToNonPk(SessionFactoryScope scope) { // also tests usage of the stand-alone @JoinFormula annotation diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/naturalid/ByteArrayNaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/naturalid/ByteArrayNaturalIdTest.java index 8ae9c067d2d3..853477d29e4b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/naturalid/ByteArrayNaturalIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/naturalid/ByteArrayNaturalIdTest.java @@ -6,10 +6,12 @@ import org.hibernate.annotations.NaturalId; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -26,6 +28,8 @@ ) @SessionFactory @JiraKey("HHH-18409") +@SkipForDialect(dialectClass = InformixDialect.class, + reason = "Blobs are not allowed in this expression (equality test with column of type BYTE)") public class ByteArrayNaturalIdTest { private static final String NATURAL_ID_1 = "N1"; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/quote/resultsetmappings/MyEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/quote/resultsetmappings/MyEntity.java index 86b2b7f2b8fa..42a8d854067a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/quote/resultsetmappings/MyEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/quote/resultsetmappings/MyEntity.java @@ -15,14 +15,12 @@ import jakarta.persistence.Table; /** - * TODO : javadoc - * * @author Steve Ebersole */ @SqlResultSetMappings({ @SqlResultSetMapping( name="explicitScalarResultSetMapping", - columns={ @ColumnResult(name="QuotEd_nAMe") } + columns= @ColumnResult( name = "\"QuotEd_nAMe\"" ) ) , @SqlResultSetMapping( diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionTest.java index 2b3b691d7196..d1895e95e72c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionTest.java @@ -12,9 +12,9 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; -import jakarta.persistence.LockTimeoutException; import jakarta.persistence.OneToMany; import jakarta.persistence.OptimisticLockException; +import jakarta.persistence.PessimisticLockException; import org.hibernate.Hibernate; import org.hibernate.collection.spi.AbstractPersistentCollection; @@ -23,9 +23,9 @@ import org.hibernate.dialect.HSQLDialect; import org.hibernate.engine.spi.CollectionEntry; +import org.hibernate.exception.LockTimeoutException; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.DomainModel; -import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; @@ -120,7 +120,7 @@ public void testCopyPersistentCollectionReferenceAfterFlush(SessionFactoryScope s2.getTransaction().commit(); fail( "should have thrown HibernateException" ); } - catch (OptimisticLockException | LockTimeoutException ex) { + catch (OptimisticLockException | PessimisticLockException | LockTimeoutException ex) { // expected s2.getTransaction().rollback(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest.java index 0bb54166691c..94728d62c2e8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest.java @@ -56,7 +56,7 @@ public class ConstraintInterpretationTest { } catch (ConstraintViolationException cve) { assertEquals( ConstraintViolationException.ConstraintKind.NOT_NULL, cve.getKind() ); - if ( !(scope.getDialect() instanceof DB2Dialect) ) { + if ( !(scope.getDialect() instanceof DB2Dialect) && !(scope.getDialect() instanceof InformixDialect) ) { assertTrue( cve.getConstraintName().toLowerCase().endsWith( "id" ) ); } } @@ -111,7 +111,9 @@ public class ConstraintInterpretationTest { } catch (ConstraintViolationException cve) { assertEquals( ConstraintViolationException.ConstraintKind.CHECK, cve.getKind() ); - assertTrue( cve.getConstraintName().toLowerCase().endsWith( "namecheck" ) ); + if ( !(scope.getDialect() instanceof InformixDialect) ) { + assertTrue( cve.getConstraintName().toLowerCase().endsWith( "namecheck" ) ); + } } } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest2.java b/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest2.java index d4df3d37765d..cb546e3d5ad3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest2.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ConstraintInterpretationTest2.java @@ -55,7 +55,7 @@ public class ConstraintInterpretationTest2 { } catch (ConstraintViolationException cve) { assertEquals( ConstraintViolationException.ConstraintKind.NOT_NULL, cve.getKind() ); - if ( !(scope.getDialect() instanceof DB2Dialect) ) { + if ( !(scope.getDialect() instanceof DB2Dialect) && !(scope.getDialect() instanceof InformixDialect) ) { assertTrue( cve.getConstraintName().toLowerCase().endsWith( "id" ) ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/BulkManipulationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/BulkManipulationTest.java index d68d1eb9cdb2..438700875a3f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/BulkManipulationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/BulkManipulationTest.java @@ -17,6 +17,7 @@ import org.hibernate.Transaction; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.CockroachDialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.MySQLDialect; @@ -301,6 +302,8 @@ public void testInsertWithNullParamValue() { @Test @JiraKey( value = "HHH-15161") + @SkipForDialect(value = InformixDialect.class, + comment = "Informix does not allow 'union' in 'insert select'") public void testInsertWithNullParamValueSetOperation() { TestData data = new TestData(); data.prepare(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/QueryComparingAssociationToNullTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/QueryComparingAssociationToNullTest.java index b5ddd4b3088a..9b4e1db5c9fa 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/QueryComparingAssociationToNullTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/QueryComparingAssociationToNullTest.java @@ -8,6 +8,7 @@ import org.hibernate.community.dialect.DerbyDialect; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.SessionFactory; @@ -31,7 +32,8 @@ ) @SessionFactory @JiraKey("HHH-16974") -@SkipForDialect( dialectClass = DerbyDialect.class, reason = "it does not like `= null`") +@SkipForDialect( dialectClass = DerbyDialect.class, reason = "it does not like '= null'") +@SkipForDialect( dialectClass = InformixDialect.class, reason = "it does not like '= null'") public class QueryComparingAssociationToNullTest { @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/size/filter/WhereAnnotatedOneToManySizeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/size/filter/WhereAnnotatedOneToManySizeTest.java index 48349a088132..dd0f21ac4832 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/size/filter/WhereAnnotatedOneToManySizeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/size/filter/WhereAnnotatedOneToManySizeTest.java @@ -8,6 +8,7 @@ import java.util.List; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.HANADialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.SybaseDialect; @@ -93,6 +94,7 @@ public void after() { @SkipForDialect(value = HANADialect.class, comment = "HANA db does not support correlated subqueries in the ORDER BY clause") @SkipForDialect(value = TiDBDialect.class, comment = "TiDB db does not support correlated subqueries in the ORDER BY clause") @SkipForDialect(value = SybaseDialect.class, comment = "Sybase db does not support subqueries in the ORDER BY clause") + @SkipForDialect(value = InformixDialect.class, comment = "Informix does not support correlated subqueries in the ORDER BY clause") public void orderBy_sizeOf() { inSession( session -> { Query query = session.createQuery( diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java index 7fd4157327a3..72b438679b8e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java @@ -12,6 +12,7 @@ import jakarta.persistence.Table; import org.hibernate.annotations.JavaType; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.OracleDialect; import org.hibernate.query.Query; @@ -33,11 +34,12 @@ * @author Piotr Krauzowicz * @author Gail Badner */ -@SkipForDialect(dialectClass = MySQLDialect.class, majorVersion = 5, matchSubTypes = true, reason = "BLOB/TEXT column 'id' used in key specification without a key length") -@SkipForDialect(dialectClass = OracleDialect.class, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key") -@DomainModel( - annotatedClasses = ByteArrayIdTest.DemoEntity.class -) +@SkipForDialect(dialectClass = MySQLDialect.class, majorVersion = 5, matchSubTypes = true, + reason = "BLOB/TEXT column 'id' used in key specification without a key length") +@SkipForDialect(dialectClass = OracleDialect.class, matchSubTypes = true, + reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key") +@SkipForDialect(dialectClass = InformixDialect.class, reason = "Cannot add index") +@DomainModel(annotatedClasses = ByteArrayIdTest.DemoEntity.class) @SessionFactory public class ByteArrayIdTest { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/immutable/ImmutableTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/immutable/ImmutableTest.java index 14007b351e60..c6c3997c6881 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/immutable/ImmutableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/immutable/ImmutableTest.java @@ -14,10 +14,12 @@ import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Environment; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.OracleDialect; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.proxy.HibernateProxy; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.AbstractSingleColumnStandardBasicType; import org.hibernate.type.descriptor.java.StringJavaType; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; @@ -1033,6 +1035,7 @@ public void testImmutableChildEntityWithMerge() { } @Test + @SkipForDialect( dialectClass = InformixDialect.class, reason = "Maximum output rowsize (32767) exceeded") public void testImmutableCollectionWithMerge() { Contract contract = new Contract( null, "gavin", "phone" ); ContractVariation contractVariation1 = new ContractVariation( 1, contract ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/ExpressionsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/ExpressionsTest.java index 907a00da7a87..78914c85a8fa 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/ExpressionsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/ExpressionsTest.java @@ -301,7 +301,7 @@ public void testSumWithSubqueryPath() { ); } - @Test @SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "numeric overflows") + @Test @SkipForDialect(dialectClass = PostgresPlusDialect.class, reason = "does not support extract(epoch)") @SkipForDialect(dialectClass = AltibaseDialect.class, reason = "datediff overflow limits") public void testDateTimeOperations() { @@ -372,6 +372,13 @@ public void testDateTimeOperations() { assertEquals( 150*60L, entityManager.createQuery(criteria).getSingleResult() ); } ); + } + + @Test + @SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "numeric overflows") + @SkipForDialect(dialectClass = PostgresPlusDialect.class, reason = "does not support extract(epoch)") + void testDurationBetween() { + HibernateCriteriaBuilder builder = (HibernateCriteriaBuilder) this.builder; doInJPA( this::entityManagerFactory, entityManager -> { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java index 80c5b902a306..7417fbcd69e6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/basic/PredicateTest.java @@ -12,6 +12,7 @@ import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Root; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.CockroachDialect; import org.hibernate.dialect.OracleDialect; import org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest; @@ -241,6 +242,8 @@ public void testCharArray() { @JiraKey( "HHH-10603" ) @SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 12, reason = "Oracle12cDialect uses blob to store byte arrays and it's not possible to compare blobs with simple equality operators.") + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "Blobs are not allowed in this expression") public void testByteArray() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metadata/TypesafeNamedQueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metadata/TypesafeNamedQueryTest.java index 49a889b67e69..a27dcbff8b2a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metadata/TypesafeNamedQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metadata/TypesafeNamedQueryTest.java @@ -5,6 +5,7 @@ package org.hibernate.orm.test.jpa.metadata; import org.hibernate.community.dialect.FirebirdDialect; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; @@ -19,6 +20,7 @@ public class TypesafeNamedQueryTest { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "'order by timestamp, id' not quite working") @SkipForDialect(dialectClass = FirebirdDialect.class, reason = "'order by timestamp, id' not quite working") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "'order by timestamp, id' not quite working") @Test void test(EntityManagerFactoryScope scope) { scope.inTransaction( entityManager -> { Record record1 = new Record("Hello, World!"); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryResultTypeAutoDiscoveryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryResultTypeAutoDiscoveryTest.java index 40a22d98f1c8..b735005f4760 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryResultTypeAutoDiscoveryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NativeQueryResultTypeAutoDiscoveryTest.java @@ -24,6 +24,7 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.community.dialect.AltibaseDialect; import org.hibernate.community.dialect.FirebirdDialect; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.HANADialect; import org.hibernate.dialect.AbstractTransactSQLDialect; import org.hibernate.dialect.CockroachDialect; @@ -155,6 +156,7 @@ public void bitType() { @SkipForDialect(dialectClass = OracleDialect.class, reason = "Oracle maps tinyint to number") @SkipForDialect(dialectClass = FirebirdDialect.class, reason = "No support for the tinyint datatype so we use smallint") @SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase maps tinyint to smallint") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "informix maps tinyint to smallint") public void tinyintType() { createEntityManagerFactory( TinyintEntity.class ); doTest( TinyintEntity.class, (byte)127 ); @@ -187,6 +189,7 @@ public void realType() { @SkipForDialect(dialectClass = HANADialect.class, matchSubTypes = true, reason = "Value is too big for the maximum allowed precision of HANA") @SkipForDialect(dialectClass = FirebirdDialect.class, reason = "Value is too big for the maximum allowed precision of Firebird") @SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Value is too big for the maximum allowed precision of Altibase") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "The scale exceeds the maximum precision specified") public void numericType() { createEntityManagerFactory( NumericEntity.class @@ -202,6 +205,7 @@ public void numericType() { @SkipForDialect(dialectClass = HANADialect.class, matchSubTypes = true, reason = "Value is too big for the maximum allowed precision of HANA") @SkipForDialect(dialectClass = FirebirdDialect.class, reason = "Value is too big for the maximum allowed precision of Firebird") @SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Value is too big for the maximum allowed precision of Altibase") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "The scale exceeds the maximum precision specified") public void decimalType() { createEntityManagerFactory( DecimalEntity.class ); doTest( DecimalEntity.class, new BigDecimal( "5464384284258458485484848458.48465843584584684" ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BooleanMappingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BooleanMappingTests.java index a6ab5840f913..b0551b54f163 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BooleanMappingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BooleanMappingTests.java @@ -9,6 +9,7 @@ import org.hibernate.boot.model.FunctionContributions; import org.hibernate.boot.model.FunctionContributor; import org.hibernate.community.dialect.AltibaseDialect; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.HANADialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.OracleDialect; @@ -355,6 +356,7 @@ public void testBooleanFunctionAsPredicate(SessionFactoryScope scope) { @SkipForDialect(dialectClass = HANADialect.class, matchSubTypes = true) @SkipForDialect(dialectClass = DB2Dialect.class, majorVersion = 10) @SkipForDialect(dialectClass = AltibaseDialect.class) + @SkipForDialect(dialectClass = InformixDialect.class) public void testBooleanFunctionInPredicate(SessionFactoryScope scope) { // Not strictly relevant to boolean mappings, but test that boolean // functions work *in a* predicate after HHH-16182 diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/InetAddressMappingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/InetAddressMappingTests.java index 089371e5982d..31da26be053f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/InetAddressMappingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/InetAddressMappingTests.java @@ -6,6 +6,7 @@ import java.net.InetAddress; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; @@ -35,7 +36,10 @@ */ @DomainModel(annotatedClasses = InetAddressMappingTests.EntityWithInetAddress.class) @SessionFactory -@SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Driver or DB omit trailing zero bytes of a varbinary, making this test fail intermittently") +@SkipForDialect(dialectClass = SybaseASEDialect.class, + reason = "Driver or DB omit trailing zero bytes of a varbinary, making this test fail intermittently") +@SkipForDialect( dialectClass = InformixDialect.class, + reason = "Blobs are not allowed in this expression (with a column of type BYTE)") public class InetAddressMappingTests { @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/enumeratedvalue/CharEnumerateValueTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/enumeratedvalue/CharEnumerateValueTests.java index f45c6323ba7d..112ee6c695b8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/enumeratedvalue/CharEnumerateValueTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/enumeratedvalue/CharEnumerateValueTests.java @@ -10,6 +10,7 @@ import java.sql.Statement; import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.SybaseDialect; import org.hibernate.type.SqlTypes; @@ -102,7 +103,10 @@ void verifyCheckConstraints(SessionFactoryScope scope) { @DomainModel(annotatedClasses = Person.class) @SessionFactory - @SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "Sybase (at least jTDS driver) truncates the value so the constraint is not violated" ) + @SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, + reason = "Sybase (at least jTDS driver) truncates the value so the constraint is not violated" ) + @SkipForDialect( dialectClass = InformixDialect.class, + reason = "Informix truncates the value so the constraint is not violated" ) @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsColumnCheck.class ) @Test void verifyCheckConstraints2(SessionFactoryScope scope) { @@ -141,7 +145,6 @@ public char getCode() { } } - @SuppressWarnings({ "FieldCanBeLocal", "unused" }) @Entity(name="Person") @Table(name="persons") public static class Person { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaFromHbmTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaFromHbmTests.java index f720af3f88d6..f1c94b26b7e2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaFromHbmTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaFromHbmTests.java @@ -6,6 +6,7 @@ import java.sql.Types; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.mapping.BasicValue; @@ -63,8 +64,12 @@ public void mappingAssertions(DomainModelScope scope) { } @Test - @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase has no trim function which is used in the mapping", matchSubTypes = true) - @SkipForDialect(dialectClass = MySQLDialect.class, reason = "The MySQL JDBC driver doesn't support the JDBC escape for the concat function which is used in the mapping", matchSubTypes = true) + @SkipForDialect(dialectClass = SybaseASEDialect.class, + reason = "Sybase has no trim function which is used in the mapping", matchSubTypes = true) + @SkipForDialect(dialectClass = MySQLDialect.class, + reason = "The MySQL JDBC driver doesn't support the JDBC escape for the concat function which is used in the mapping", matchSubTypes = true) + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The Informix JDBC driver doesn't support the JDBC escape for the concat function which is used in the mapping") public void testBasicHqlUse(SessionFactoryScope scope) { scope.inTransaction( (session) -> session.createQuery( "from EntityOfFormulas" ).list() diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaTests.java index 60eb68273329..50d42109a738 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaTests.java @@ -14,6 +14,7 @@ import org.hibernate.annotations.Formula; import org.hibernate.community.dialect.FirebirdDialect; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.community.dialect.DerbyDialect; import org.hibernate.dialect.HSQLDialect; @@ -119,6 +120,8 @@ public static class Account { override = @Formula("ltrim(str(rate * 100, 10, 2)) + '%'")) @DialectOverride.Formula(dialect = FirebirdDialect.class, override = @Formula("cast(rate * 100 as decimal(10,2)) || '%'")) + @DialectOverride.Formula(dialect = InformixDialect.class, + override = @Formula("trim(concat(to_char(rate * 100,'#&.&&'), '%'))")) private String ratePercent; public Long getId() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java index 618aeb0a8ba3..c24ea05f33c1 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java @@ -35,7 +35,8 @@ */ @DomainModel( annotatedClasses = InDbGenerationsWithAnnotationsTests.AuditedEntity.class ) @SessionFactory -@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp") +@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, + comment = "Without this, we might not see an update to the timestamp") public class InDbGenerationsWithAnnotationsTests { @Test public void testGenerations(SessionFactoryScope scope) { @@ -57,9 +58,7 @@ public void testGenerations(SessionFactoryScope scope) { waitALittle(); // then changing - final AuditedEntity merged = scope.fromTransaction( session, (s) -> { - return (AuditedEntity) session.merge( saved ); - } ); + final AuditedEntity merged = scope.fromTransaction( session, s -> s.merge( saved ) ); assertThat( merged ).isNotNull(); assertThat( merged.createdOn ).isNotNull(); @@ -69,10 +68,8 @@ public void testGenerations(SessionFactoryScope scope) { //We need to wait a little to make sure the timestamps produced are different waitALittle(); - // lastly, make sure we can load it.. - final AuditedEntity loaded = scope.fromTransaction( session, (s) -> { - return session.get( AuditedEntity.class, 1 ); - } ); + // lastly, make sure we can load it + final AuditedEntity loaded = scope.fromTransaction( session, s -> s.get( AuditedEntity.class, 1 ) ); assertThat( loaded ).isNotNull(); assertThat( loaded.createdOn ).isEqualTo( merged.createdOn ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/multitenancy/SchemaBasedMultitenancyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/multitenancy/SchemaBasedMultitenancyTest.java index df7d0b72faad..73b92354c0b2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/multitenancy/SchemaBasedMultitenancyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/multitenancy/SchemaBasedMultitenancyTest.java @@ -7,6 +7,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.Id; import org.checkerframework.checker.nullness.qual.NonNull; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.context.spi.TenantSchemaMapper; import org.hibernate.dialect.SQLServerDialect; @@ -35,6 +36,7 @@ @RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class) @SkipForDialect(dialectClass = SQLServerDialect.class, reason = "Warning: setSchema is a no-op in this driver version") @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "getSchema() method not implemented by jTDS") +@SkipForDialect(dialectClass = InformixDialect.class, reason = "setSchema() method is a noop") @JiraKey("HHH-19559") public class SchemaBasedMultitenancyTest { private static String currentTenantIdentifier; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java index de9548ca2867..dd124cdc3cc1 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java @@ -168,7 +168,9 @@ void testSimpleMutationRestriction(SessionFactoryScope factoryScope) { assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); assertThat( sqlCollector.getSqlQueries().get( 0 ) ) - .containsAnyOf( " where be1_0.position between ? and ?", " where be1_0.\"position\" between ? and ?" ); + .containsAnyOf( " where be1_0.position between ? and ?", + " where be1_0.\"position\" between ? and ?", + " where position between ? and ?" ); } @Test @@ -225,7 +227,9 @@ void testSimpleMutationRestrictionAsReference(SessionFactoryScope factoryScope) assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); assertThat( sqlCollector.getSqlQueries().get( 0 ) ) - .containsAnyOf( " where be1_0.position between ? and ?", " where be1_0.\"position\" between ? and ?" ); + .containsAnyOf( " where be1_0.position between ? and ?", + " where be1_0.\"position\" between ? and ?", + " where position between ? and ?" ); } @Test @@ -242,7 +246,9 @@ void testSimpleMutationRestrictionStatelessAsReference(SessionFactoryScope facto assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); assertThat( sqlCollector.getSqlQueries().get( 0 ) ) - .containsAnyOf( " where be1_0.position between ? and ?", " where be1_0.\"position\" between ? and ?" ); + .containsAnyOf( " where be1_0.position between ? and ?", + " where be1_0.\"position\" between ? and ?", + " where position between ? and ?" ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java index 431fec0e043a..0e33c49724c5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java @@ -72,8 +72,10 @@ import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.isOneOf; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hibernate.testing.orm.domain.gambit.EntityOfBasics.Gender.FEMALE; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -1176,6 +1178,7 @@ public void testCastFunctionWithLength(SessionFactoryScope scope) { @SkipForDialect(dialectClass = OracleDialect.class, reason = "Oracle cast to raw does not do truncation") @SkipForDialect(dialectClass = DB2Dialect.class, majorVersion = 10, minorVersion = 5, reason = "On this version the length of the cast to the parameter appears to be > 2") @SkipForDialect(dialectClass = HSQLDialect.class, reason = "HSQL interprets string as hex literal and produces error") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "No cast from varchar to byte") public void testCastBinaryWithLength(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -1190,6 +1193,7 @@ public void testCastBinaryWithLength(SessionFactoryScope scope) { @Test @SkipForDialect(dialectClass = DerbyDialect.class, reason = "Derby doesn't support casting varchar to binary") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix does not support binary literals") public void testCastBinaryWithLengthForOracle(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -1202,6 +1206,7 @@ public void testCastBinaryWithLengthForOracle(SessionFactoryScope scope) { @Test @SkipForDialect(dialectClass = PostgreSQLDialect.class, matchSubTypes = true, reason = "PostgreSQL bytea doesn't have a length") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix does not support binary literals") public void testCastBinaryWithLengthForDerby(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -2119,6 +2124,7 @@ public void testExtractFunction(SessionFactoryScope scope) { } @Test + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExtractDayOfWeekYearMonth.class) public void testExtractFunctionDayOfWeekOf(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -2140,14 +2146,21 @@ public void testExtractFunctionDayOfWeekOf(SessionFactoryScope scope) { public void testExtractFunctionEpoch(SessionFactoryScope scope) { scope.inTransaction( session -> { - session.createQuery("select extract(epoch from local datetime)", Long.class).getSingleResult(); + long before = Instant.now().getEpochSecond()-1; + long epoch = session.createQuery( "select extract(epoch from local datetime)", Long.class ).getSingleResult(); + long after = Instant.now().getEpochSecond()+1; + assertThat( epoch, allOf( greaterThanOrEqualTo( before ), lessThanOrEqualTo( after ) ) ); + session.createQuery("select extract(epoch from offset datetime)", Long.class).getSingleResult(); - assertThat( session.createQuery("select extract(epoch from datetime 1974-03-23 12:35)", Long.class).getSingleResult(), is(133274100L) ); + + assertThat( session.createQuery("select extract(epoch from datetime 1974-03-23 12:35)", Long.class).getSingleResult(), + is(133274100L) ); } ); } @Test + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExtractDayOfWeekYearMonth.class) public void testExtractFunctionWeek(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -2201,7 +2214,8 @@ public void testExtractFunctionTimeZoneOffset(SessionFactoryScope scope) { } @Test - public void testExtractFunctionWithAssertions(SessionFactoryScope scope) { + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExtractDayOfWeekYearMonth.class) + public void testExtractWeekWithAssertions(SessionFactoryScope scope) { scope.inTransaction( session -> { assertThat( @@ -2247,6 +2261,14 @@ public void testExtractFunctionWithAssertions(SessionFactoryScope scope) { session.createQuery("select extract(day of year from date 2019-05-30) from EntityOfBasics", Integer.class).getResultList().get(0), is(150) ); + } + ); + } + + @Test + public void testExtractFunctionWithAssertions(SessionFactoryScope scope) { + scope.inTransaction( + session -> { assertThat( session.createQuery("select extract(day of month from date 2019-05-27) from EntityOfBasics", Integer.class).getResultList().get(0), is(27) @@ -2587,6 +2609,7 @@ public void testSlice(SessionFactoryScope scope) { @SkipForDialect(dialectClass = DerbyDialect.class) @SkipForDialect(dialectClass = HSQLDialect.class) @SkipForDialect(dialectClass = DB2Dialect.class) + @SkipForDialect(dialectClass = InformixDialect.class) public void testNullInCoalesce(SessionFactoryScope scope) { scope.inTransaction(s -> { assertEquals("hello", @@ -2665,6 +2688,7 @@ public void testSha256Function(SessionFactoryScope scope) { @Test @SkipForDialect(dialectClass = SybaseASEDialect.class) + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix does not support binary literals") public void testHexFunction(SessionFactoryScope scope) { scope.inTransaction(s -> { assertEquals( "DEADBEEF", diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/HqlUnionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/HqlUnionTest.java index dccc913089d7..38b491c8cf87 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/HqlUnionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/HqlUnionTest.java @@ -6,6 +6,7 @@ import java.util.List; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.testing.orm.junit.JiraKey; @@ -13,7 +14,8 @@ import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Entity; @@ -30,9 +32,10 @@ @SessionFactory @JiraKey(value = "HHH-15766") @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE does not support order by in subqueries") +@SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix does not support order by in subqueries") public class HqlUnionTest { - @BeforeAll + @BeforeEach public void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -47,6 +50,11 @@ public void setUp(SessionFactoryScope scope) { ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testUnionQueryWithOrderBy(SessionFactoryScope scope) { scope.inTransaction( diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/InsertConflictTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/InsertConflictTests.java index 7ff0a90bae8b..3a81fe3ba74f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/InsertConflictTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/InsertConflictTests.java @@ -6,6 +6,7 @@ import java.time.LocalDate; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.query.criteria.HibernateCriteriaBuilder; @@ -108,6 +109,7 @@ public void testOnConflictDoUpdate(SessionFactoryScope scope) { @Test @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUpsertOrMerge.class) + @SkipForDialect(dialectClass = InformixDialect.class, reason = "MATCHED does not support AND condition") public void testOnConflictDoUpdateWithWhere(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -138,6 +140,7 @@ else if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof Sy @Test @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUpsertOrMerge.class) + @SkipForDialect(dialectClass = InformixDialect.class, reason = "MATCHED does not support AND condition") public void testOnConflictDoUpdateWithWhereCriteria(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -228,6 +231,7 @@ public void testOnConflictDoUpdateMultiTable(SessionFactoryScope scope) { @Test @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUpsertOrMerge.class) @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "MERGE into a table that has a self-referential FK does not work") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "MATCHED does not support AND condition") public void testOnConflictDoUpdateWithWhereMultiTable(SessionFactoryScope scope) { scope.inTransaction( session -> { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java index 2d40ba8bf24f..95eaf9358960 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/MultiValuedParameterTest.java @@ -12,21 +12,22 @@ import java.util.List; import org.hibernate.boot.MetadataSources; -import org.hibernate.query.Query; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.testing.orm.domain.contacts.Contact; import org.hibernate.testing.orm.domain.contacts.ContactsDomainModel; import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest; import org.hibernate.testing.orm.junit.Jira; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.hibernate.testing.orm.junit.SkipForDialect; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Entity; import jakarta.persistence.Id; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -41,7 +42,7 @@ protected void applyMetadataSources(MetadataSources metadataSources) { metadataSources.addAnnotatedClass( EntityWithNumericId.class ); } - @BeforeAll + @BeforeEach public void prepareData() { inTransaction( session -> { @@ -66,8 +67,8 @@ public void prepareData() { public void testParameterListIn() { inTransaction( session -> { + var q = session.createQuery( "select id from Contact where id in (:ids) order by id" ); Collection ids = new ArrayList<>(); - Query q = session.createQuery( "select id from Contact where id in (:ids) order by id" ); for ( int i = 0; i < 10; i++ ) { ids.add( i ); } @@ -104,6 +105,8 @@ public void test() { @Test @Jira( "https://hibernate.atlassian.net/browse/HHH-18575" ) + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "Informix does not like '? in (?,?)'") void testMultiValuedBigDecimals() { inTransaction( session -> { assertEquals( @@ -116,12 +119,9 @@ void testMultiValuedBigDecimals() { }); } - @AfterAll + @AfterEach public void cleanupData() { - inTransaction( session -> { - session.createMutationQuery( "delete Contact" ).executeUpdate(); - session.createMutationQuery( "delete EntityWithNumericId" ).executeUpdate(); - } ); + sessionFactoryScope().getSessionFactory().getSchemaManager().truncate(); } @Entity( name = "EntityWithNumericId" ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/StandardFunctionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/StandardFunctionTests.java index 2bec6419a9b7..211d14bc7d27 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/StandardFunctionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/StandardFunctionTests.java @@ -25,7 +25,8 @@ import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.anyOf; @@ -45,7 +46,7 @@ @SessionFactory public class StandardFunctionTests { - @BeforeAll + @BeforeEach public void prepareData(SessionFactoryScope scope) { scope.inTransaction( em -> { @@ -60,6 +61,11 @@ public void prepareData(SessionFactoryScope scope) { ); } + @AfterEach + public void truncateDate(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void currentTimestampTests(SessionFactoryScope scope) { scope.inTransaction( @@ -582,6 +588,7 @@ public void testIntervalDiffExpressionsDifferentTypes(SessionFactoryScope scope) } @Test + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExtractDayOfWeekYearMonth.class) public void testExtractFunction(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -683,7 +690,7 @@ public void isolated(SessionFactoryScope scope) { } @Test -// @FailureExpected + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExtractDayOfWeekYearMonth.class) public void testExtractFunctionWithAssertions(SessionFactoryScope scope) { scope.inTransaction( session -> { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryResultBuilderTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryResultBuilderTests.java index bb7a92c31821..084ba369f417 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryResultBuilderTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryResultBuilderTests.java @@ -10,6 +10,7 @@ import java.time.Instant; import java.util.List; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.community.dialect.DerbyDialect; import org.hibernate.dialect.OracleDialect; @@ -20,6 +21,7 @@ import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; import org.hibernate.query.NativeQuery; import org.hibernate.testing.orm.domain.gambit.BasicEntity; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; @@ -34,7 +36,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.assertj.core.api.Assumptions; import org.hamcrest.CustomMatcher; import org.hamcrest.Matcher; @@ -79,17 +80,17 @@ public void fullyImplicitTest(SessionFactoryScope scope) { } @Test + // DB2, Derby, SQL Server and Sybase return an Integer for count by default + // Oracle returns a NUMERIC(39,0) i.e. a BigDecimal for count by default + @SkipForDialect(dialectClass = DB2Dialect.class) + @SkipForDialect(dialectClass = DerbyDialect.class) + @SkipForDialect(dialectClass = SQLServerDialect.class) + @SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true) + @SkipForDialect(dialectClass = OracleDialect.class) + @SkipForDialect(dialectClass = InformixDialect.class) public void fullyImplicitTest2(SessionFactoryScope scope) { scope.inTransaction( session -> { - // DB2, Derby, SQL Server and Sybase return an Integer for count by default - // Oracle returns a NUMERIC(39,0) i.e. a BigDecimal for count by default - Assumptions.assumeThat( session.getJdbcServices().getDialect() ) - .isNotInstanceOf( DB2Dialect.class ) - .isNotInstanceOf( DerbyDialect.class ) - .isNotInstanceOf( SQLServerDialect.class ) - .isNotInstanceOf( SybaseDialect.class ) - .isNotInstanceOf( OracleDialect.class ); final String sql = "select count(the_string) from EntityOfBasics"; final NativeQuery query = session.createNativeQuery( sql ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/foreignkeys/JoinedInheritanceForeignKeyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/foreignkeys/JoinedInheritanceForeignKeyTest.java index 85d1dedc7fd7..a3810c9e4488 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/foreignkeys/JoinedInheritanceForeignKeyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/foreignkeys/JoinedInheritanceForeignKeyTest.java @@ -26,9 +26,11 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.schema.TargetType; @@ -66,6 +68,8 @@ public void tearsDown() { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason="Informix has a strange syntax for 'alter table ... add constraint'") public void testForeignKeyHasCorrectName() throws Exception { createSchema( new Class[] {Role.class, User.class, Person.class} ); checkAlterTableStatement( new AlterTableStatement( diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneJoinTableTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneJoinTableTest.java index d93e5f9700b8..8d36d6a23fe3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneJoinTableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneJoinTableTest.java @@ -38,15 +38,18 @@ @SessionFactory(generateStatistics = true) public class EntityWithOneToOneJoinTableTest { + final int maxInt = Integer.MAX_VALUE - 1; + final int minInt = Integer.MIN_VALUE + 1; + @BeforeEach public void setUp(SessionFactoryScope scope) { - EntityWithOneToOneJoinTable entity = new EntityWithOneToOneJoinTable( 1, "first", Integer.MAX_VALUE ); + EntityWithOneToOneJoinTable entity = new EntityWithOneToOneJoinTable( 1, "first", maxInt ); SimpleEntity other = new SimpleEntity( 2, Calendar.getInstance().getTime(), null, - Integer.MAX_VALUE, + maxInt, Long.MAX_VALUE, null ); @@ -65,7 +68,7 @@ public void setUp(SessionFactoryScope scope) { EntityWithOneToOneJoinTable entity2 = new EntityWithOneToOneJoinTable( 2, "second", - Integer.MAX_VALUE + maxInt ); SimpleEntity other2 = new SimpleEntity( @@ -115,7 +118,7 @@ public void testGet(SessionFactoryScope scope) { session -> { final SimpleEntity loaded = session.get( SimpleEntity.class, 2 ); assert loaded != null; - assertThat( loaded.getSomeInteger(), equalTo( Integer.MAX_VALUE ) ); + assertThat( loaded.getSomeInteger(), equalTo( maxInt ) ); } ); } @@ -225,7 +228,7 @@ public void testHqlSelectParentWithJoinFetch(SessionFactoryScope scope) { @Test public void testUpdate(SessionFactoryScope scope) { - EntityWithOneToOneJoinTable entity = new EntityWithOneToOneJoinTable( 3, "first", Integer.MAX_VALUE ); + EntityWithOneToOneJoinTable entity = new EntityWithOneToOneJoinTable( 3, "first", maxInt ); SimpleEntity other = new SimpleEntity( 4, @@ -249,7 +252,7 @@ public void testUpdate(SessionFactoryScope scope) { 5, Calendar.getInstance().getTime(), null, - Integer.MIN_VALUE, + minInt, Long.MAX_VALUE, null ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneTest.java index 9174793066b0..b54f80714f77 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/exec/onetoone/EntityWithOneToOneTest.java @@ -40,15 +40,18 @@ @SessionFactory(generateStatistics = true) public class EntityWithOneToOneTest { + final int maxInt = Integer.MAX_VALUE - 1; + final int minInt = Integer.MIN_VALUE + 1; + @BeforeEach public void setUp(SessionFactoryScope scope) { - EntityWithOneToOne entity = new EntityWithOneToOne( 1, "first", Integer.MAX_VALUE ); + EntityWithOneToOne entity = new EntityWithOneToOne( 1, "first", maxInt ); SimpleEntity other = new SimpleEntity( 2, Calendar.getInstance().getTime(), null, - Integer.MAX_VALUE, + maxInt, Long.MAX_VALUE, null ); @@ -91,7 +94,7 @@ public void testGet(SessionFactoryScope scope) { session -> { final SimpleEntity loaded = session.get( SimpleEntity.class, 2 ); assert loaded != null; - assertThat( loaded.getSomeInteger(), equalTo( Integer.MAX_VALUE ) ); + assertThat( loaded.getSomeInteger(), equalTo( maxInt ) ); } ); } @@ -102,7 +105,7 @@ public void testUpdate(SessionFactoryScope scope) { 3, Calendar.getInstance().getTime(), null, - Integer.MIN_VALUE, + minInt, Long.MIN_VALUE, null ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicListTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicListTest.java index 114da4b49dee..db83ae18c97d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicListTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicListTest.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.List; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -25,7 +26,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -54,7 +56,7 @@ public class BasicListTest { private BasicType> integerListType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { integerListType = em.getTypeConfiguration().getBasicTypeForGenericJavaType( List.class, Integer.class ); @@ -75,6 +77,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -101,6 +108,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithIntegerList.JPQL.getByData", TableWithIntegerList.class ); @@ -128,6 +137,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicSortedSetTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicSortedSetTest.java index 829cfea04354..84fb9ce2e58c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicSortedSetTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicSortedSetTest.java @@ -9,6 +9,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -26,7 +27,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -55,7 +57,7 @@ public class BasicSortedSetTest { private BasicType> integerSortedSetType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { integerSortedSetType = em.getTypeConfiguration().getBasicTypeForGenericJavaType( SortedSet.class, Integer.class ); @@ -76,6 +78,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -102,6 +109,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithIntegerSortedSet.JPQL.getByData", TableWithIntegerSortedSet.class ); @@ -129,6 +138,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayTest.java index cbb7b9df499d..9790a87d1aef 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayTest.java @@ -4,6 +4,7 @@ */ package org.hibernate.orm.test.type; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -25,7 +26,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -57,7 +59,7 @@ public class BooleanArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( Boolean[].class ); @@ -78,6 +80,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test @SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required") public void testById(SessionFactoryScope scope) { @@ -107,6 +114,8 @@ public void testQueryById(SessionFactoryScope scope) { @Test @SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required") + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithBooleanArrays.JPQL.getByData", TableWithBooleanArrays.class ); @@ -135,6 +144,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/DateArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/DateArrayTest.java index e222731e81a3..251e65656330 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/DateArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/DateArrayTest.java @@ -6,6 +6,7 @@ import java.time.LocalDate; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -25,7 +26,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -61,7 +63,7 @@ public class DateArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( LocalDate[].class ); @@ -87,6 +89,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -117,6 +124,8 @@ public void testQueryById(SessionFactoryScope scope) { @Test @SkipForDialect(dialectClass = PostgresPlusDialect.class, reason = "Seems that comparing date[] through JDBC is buggy. ERROR: operator does not exist: timestamp without time zone[] = date[]") + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithDateArrays.JPQL.getByData", TableWithDateArrays.class ); @@ -145,6 +154,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") @SkipForDialect(dialectClass = PostgresPlusDialect.class, reason = "Seems that comparing date[] through JDBC is buggy. ERROR: operator does not exist: timestamp without time zone[] = date[]") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/DoubleArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/DoubleArrayTest.java index 3b89de0ff871..227165cf57b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/DoubleArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/DoubleArrayTest.java @@ -5,6 +5,7 @@ package org.hibernate.orm.test.type; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -23,7 +24,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -54,7 +56,7 @@ public class DoubleArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( Double[].class ); @@ -77,6 +79,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testLoadValueWithInexactFloatRepresentation(SessionFactoryScope scope) { scope.inSession( em -> { @@ -112,6 +119,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithDoubleArrays.JPQL.getByData", TableWithDoubleArrays.class ); @@ -139,6 +148,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumArrayTest.java index 2a0c3d587a5c..d64eff5b56fb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumArrayTest.java @@ -5,6 +5,7 @@ package org.hibernate.orm.test.type; import org.hibernate.community.dialect.AltibaseDialect; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.community.dialect.DerbyDialect; import org.hibernate.dialect.Dialect; @@ -22,7 +23,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -54,7 +56,7 @@ public class EnumArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( MyEnum[].class ); @@ -75,6 +77,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test @SkipForDialect(dialectClass = AltibaseDialect.class, reason = "When length 0 byte array is inserted, Altibase returns with null") public void testById(SessionFactoryScope scope) { @@ -103,6 +110,8 @@ public void testQueryById(SessionFactoryScope scope) { @Test @SkipForDialect(dialectClass = AltibaseDialect.class, reason = "When length 0 byte array is inserted, Altibase returns with null") + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithEnumArrays.JPQL.getByData", TableWithEnumArrays.class ); @@ -132,6 +141,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") @SkipForDialect(dialectClass = DerbyDialect.class ) @SkipForDialect(dialectClass = DB2Dialect.class ) + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetConverterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetConverterTest.java index d2b2b311b84c..371c6d08260d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetConverterTest.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.Set; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -26,7 +27,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.AttributeConverter; @@ -57,7 +59,7 @@ public class EnumSetConverterTest { private BasicType> enumSetType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { //noinspection unchecked @@ -84,6 +86,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -110,6 +117,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithEnumSetConverter.JPQL.getByData", TableWithEnumSetConverter.class ); @@ -137,6 +146,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetTest.java index 7657d45c477c..00ccd1528acb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/EnumSetTest.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.Set; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -25,7 +26,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -56,7 +58,7 @@ public class EnumSetTest { private BasicType> enumSetType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { enumSetType = em.getTypeConfiguration().getBasicTypeForGenericJavaType( Set.class, MyEnum.class ); @@ -77,6 +79,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -103,6 +110,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithEnumSet.JPQL.getByData", TableWithEnumSet.class ); @@ -130,6 +139,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/FloatArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/FloatArrayTest.java index 8eddb68438e3..cfb915e88375 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/FloatArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/FloatArrayTest.java @@ -4,6 +4,7 @@ */ package org.hibernate.orm.test.type; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -22,7 +23,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -53,7 +55,7 @@ public class FloatArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( Float[].class ); @@ -74,6 +76,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -100,6 +107,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithFloatArrays.JPQL.getByData", TableWithFloatArrays.class ); @@ -127,6 +136,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/IntegerArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/IntegerArrayTest.java index 772fca107039..8c78c0639872 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/IntegerArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/IntegerArrayTest.java @@ -4,6 +4,7 @@ */ package org.hibernate.orm.test.type; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -22,7 +23,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -53,7 +55,7 @@ public class IntegerArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( Integer[].class ); @@ -74,6 +76,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -100,6 +107,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithIntegerArrays.JPQL.getByData", TableWithIntegerArrays.class ); @@ -127,6 +136,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/LongArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/LongArrayTest.java index bfb4751b1b0e..30c0c4dc9126 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/LongArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/LongArrayTest.java @@ -4,6 +4,7 @@ */ package org.hibernate.orm.test.type; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -22,7 +23,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -53,7 +55,7 @@ public class LongArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( Long[].class ); @@ -76,6 +78,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -105,6 +112,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithLongArrays.JPQL.getByData", TableWithLongArrays.class ); @@ -132,6 +141,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/ShortArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/ShortArrayTest.java index 7cf82ab88f32..fd153ae9917c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/ShortArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/ShortArrayTest.java @@ -4,6 +4,7 @@ */ package org.hibernate.orm.test.type; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -22,7 +23,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -53,7 +55,7 @@ public class ShortArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( Short[].class ); @@ -74,6 +76,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -100,6 +107,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithShortArrays.JPQL.getByData", TableWithShortArrays.class ); @@ -127,6 +136,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/StringArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/StringArrayTest.java index 3d99ad482220..e0418e99af85 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/StringArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/StringArrayTest.java @@ -4,6 +4,7 @@ */ package org.hibernate.orm.test.type; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -127,6 +128,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimeArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimeArrayTest.java index 1e1ea1f77cd6..b99c6e06a174 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimeArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimeArrayTest.java @@ -6,6 +6,7 @@ import java.time.LocalTime; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -24,7 +25,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -60,7 +62,7 @@ public class TimeArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( LocalTime[].class ); @@ -85,6 +87,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -114,6 +121,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithTimeArrays.JPQL.getByData", TableWithTimeArrays.class ); @@ -141,6 +150,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimestampArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimestampArrayTest.java index 7c2e8a46cce4..388e49fe0a5c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimestampArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/TimestampArrayTest.java @@ -7,6 +7,7 @@ import java.time.LocalDateTime; import java.time.Month; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HANADialect; @@ -25,7 +26,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.type.BasicType; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; @@ -61,7 +63,7 @@ public class TimestampArrayTest { private BasicType arrayType; - @BeforeAll + @BeforeEach public void startUp(SessionFactoryScope scope) { scope.inTransaction( em -> { arrayType = em.getTypeConfiguration().getBasicTypeForJavaType( LocalDateTime[].class ); @@ -90,6 +92,11 @@ public void startUp(SessionFactoryScope scope) { } ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @Test public void testById(SessionFactoryScope scope) { scope.inSession( em -> { @@ -119,6 +126,8 @@ public void testQueryById(SessionFactoryScope scope) { } @Test + @SkipForDialect(dialectClass = InformixDialect.class, + reason = "The statement failed because binary large objects are not allowed in the Union, Intersect, or Minus ") public void testQuery(SessionFactoryScope scope) { scope.inSession( em -> { TypedQuery tq = em.createNamedQuery( "TableWithTimestampArrays.JPQL.getByData", TableWithTimestampArrays.class ); @@ -146,6 +155,7 @@ public void testNativeQueryById(SessionFactoryScope scope) { @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE requires a special function to compare XML") @SkipForDialect(dialectClass = HANADialect.class, reason = "HANA requires a special function to compare LOBs") @SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL supports distinct from through a special operator") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix can't compare LOBs") public void testNativeQuery(SessionFactoryScope scope) { scope.inSession( em -> { final Dialect dialect = em.getDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java index 57aae409ccbf..6292e99cdb8e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java @@ -11,6 +11,7 @@ import java.util.stream.Stream; import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.HANADialect; import org.hibernate.dialect.SybaseDialect; import org.hibernate.type.SqlTypes; @@ -20,7 +21,8 @@ import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -42,7 +44,7 @@ @SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true) public class VarbinaryArrayTest { - @BeforeAll + @BeforeEach void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { EntityWithArrays entity; @@ -186,6 +188,11 @@ Stream perTypeArguments() { ); } + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncate(); + } + @ParameterizedTest @MethodSource("perTypeArguments") void loadById(String propertyName, long id, T value, Function getter, @@ -212,7 +219,10 @@ void queryById(String propertyName, long id, T value, Function void queryByData(String propertyName, long id, T value, Function getter, SessionFactoryScope scope) { scope.inTransaction( session -> { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java index 922cdde97766..4e73777ac1cc 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java @@ -445,8 +445,8 @@ public boolean apply(Dialect dialect) { public static class SupportsOrderByInCorrelatedSubquery implements DialectFeatureCheck { public boolean apply(Dialect dialect) { return dialect.supportsOrderByInSubquery() - // For some reason, HANA doesn't support order by in correlated subqueries... - && !( dialect instanceof HANADialect ); + // HANA doesn't support 'order by' in correlated subqueries + && !( dialect instanceof HANADialect ); } } @@ -458,7 +458,8 @@ public boolean apply(Dialect dialect) { public static class CurrentTimestampHasMicrosecondPrecision implements DialectFeatureCheck { public boolean apply(Dialect dialect) { - return !dialect.currentTimestamp().contains( "6" ); + return dialect.getDefaultTimestampPrecision() >= 6 + && !( dialect instanceof MySQLDialect ); // For MySQL you have to explicitly ask for microseconds } } @@ -477,15 +478,15 @@ public boolean apply(Dialect dialect) { public static class SupportsStringAggregation implements DialectFeatureCheck { public boolean apply(Dialect dialect) { return dialect instanceof H2Dialect - || dialect instanceof HSQLDialect - || dialect instanceof MySQLDialect - || dialect instanceof PostgreSQLDialect - || dialect instanceof HANADialect - || dialect instanceof CockroachDialect - || dialect instanceof DB2Dialect - || dialect instanceof OracleDialect - || dialect instanceof SpannerDialect - || dialect instanceof SQLServerDialect; + || dialect instanceof HSQLDialect + || dialect instanceof MySQLDialect + || dialect instanceof PostgreSQLDialect + || dialect instanceof HANADialect + || dialect instanceof CockroachDialect + || dialect instanceof DB2Dialect + || dialect instanceof OracleDialect + || dialect instanceof SpannerDialect + || dialect instanceof SQLServerDialect; } } @@ -495,7 +496,7 @@ public boolean apply(Dialect dialect) { || dialect instanceof PostgreSQLDialect || dialect instanceof HANADialect || dialect instanceof CockroachDialect - || dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isSameOrAfter( 11 ) + || dialect instanceof DB2Dialect db2 && db2.getDB2Version().isSameOrAfter( 11 ) || dialect instanceof OracleDialect || dialect instanceof SpannerDialect || dialect instanceof SQLServerDialect; @@ -508,7 +509,7 @@ public boolean apply(Dialect dialect) { || dialect instanceof PostgreSQLDialect || dialect instanceof HANADialect || dialect instanceof CockroachDialect - || dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isSameOrAfter( 11 ) + || dialect instanceof DB2Dialect db2 && db2.getDB2Version().isSameOrAfter( 11 ) || dialect instanceof OracleDialect || dialect instanceof SpannerDialect || dialect instanceof SQLServerDialect; @@ -518,13 +519,13 @@ public boolean apply(Dialect dialect) { public static class SupportsWindowFunctions implements DialectFeatureCheck { public boolean apply(Dialect dialect) { // Derby doesn't really support window functions, only row_number() - return dialect.supportsWindowFunctions() && !( dialect instanceof DerbyDialect ); + return dialect.supportsWindowFunctions() + && !( dialect instanceof DerbyDialect ); } } public static class SupportsFilterClause implements DialectFeatureCheck { public boolean apply(Dialect dialect) { - // Derby doesn't really support window functions, only row_number() return dialect instanceof PostgreSQLDialect; } } @@ -538,7 +539,6 @@ public boolean apply(Dialect dialect) { public static class SupportsFullJoin implements DialectFeatureCheck { public boolean apply(Dialect dialect) { - // TiDB db does not support subqueries for ON condition return !( dialect instanceof H2Dialect || dialect instanceof MySQLDialect || dialect instanceof SybaseDialect @@ -552,7 +552,14 @@ public boolean apply(Dialect dialect) { || dialect instanceof SybaseDialect || dialect instanceof DerbyDialect || dialect instanceof FirebirdDialect - || dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) ); + || dialect instanceof InformixDialect + || dialect instanceof DB2Dialect db2 && db2.getDB2Version().isBefore( 11 ) ); + } + } + + public static class SupportsExtractDayOfWeekYearMonth implements DialectFeatureCheck { + public boolean apply(Dialect dialect) { + return !( dialect instanceof InformixDialect ); } } @@ -696,9 +703,9 @@ public boolean apply(Dialect dialect) { public static class SupportsJsonQueryNestedPath implements DialectFeatureCheck { public boolean apply(Dialect dialect) { return definesFunction( dialect, "json_query" ) - && !( dialect instanceof SQLServerDialect ) - && !( dialect instanceof H2Dialect ) - && !( dialect instanceof CockroachDialect ); + && !( dialect instanceof SQLServerDialect ) + && !( dialect instanceof H2Dialect ) + && !( dialect instanceof CockroachDialect ); } } @@ -723,14 +730,14 @@ public boolean apply(Dialect dialect) { public static class SupportsJsonValueErrorBehavior implements DialectFeatureCheck { public boolean apply(Dialect dialect) { return definesFunction( dialect, "json_value" ) - // H2 emulation doesn't support error behavior - && !( dialect instanceof H2Dialect ) - // MariaDB simply doesn't support the on error and on empty clauses - && !( dialect instanceof MariaDBDialect ) - // Cockroach doesn't have a native json_value function - && !( dialect instanceof CockroachDialect ) - // PostgreSQL added support for native json_value in version 17 - && ( !( dialect instanceof PostgreSQLDialect ) || dialect.getVersion().isSameOrAfter( 17 ) ); + // H2 emulation doesn't support error behavior + && !( dialect instanceof H2Dialect ) + // MariaDB simply doesn't support the on error and on empty clauses + && !( dialect instanceof MariaDBDialect ) + // Cockroach doesn't have a native json_value function + && !( dialect instanceof CockroachDialect ) + // PostgreSQL added support for native json_value in version 17 + && !( dialect instanceof PostgreSQLDialect && dialect.getVersion().isBefore( 17 ) ); } } @@ -743,8 +750,8 @@ public boolean apply(Dialect dialect) { public static class SupportsJsonObjectAgg implements DialectFeatureCheck { public boolean apply(Dialect dialect) { return definesFunction( dialect, "json_objectagg" ) - // Bug in HSQL: https://sourceforge.net/p/hsqldb/bugs/1718/ - && !( dialect instanceof HSQLDialect ); + // Bug in HSQL: https://sourceforge.net/p/hsqldb/bugs/1718/ + && !( dialect instanceof HSQLDialect ); } } diff --git a/local-build-plugins/src/main/groovy/local.databases.gradle b/local-build-plugins/src/main/groovy/local.databases.gradle index 150ec7f19236..38d66af05d7f 100644 --- a/local-build-plugins/src/main/groovy/local.databases.gradle +++ b/local-build-plugins/src/main/groovy/local.databases.gradle @@ -34,7 +34,7 @@ ext { 'connection.init_sql' : '' ], derby : [ - 'db.dialect' : 'org.hibernate.dialect.DerbyDialect', + 'db.dialect' : 'org.hibernate.community.dialect.DerbyDialect', 'jdbc.driver': 'org.apache.derby.iapi.jdbc.AutoloadedDriver', 'jdbc.user' : 'hibernate_orm_test', 'jdbc.pass' : 'hibernate_orm_test',