diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java index f74fad6da5..2e93671f41 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacySqlAstTranslator.java @@ -433,12 +433,47 @@ public class OracleLegacySqlAstTranslator extends Abstr rhs.accept( this ); appendSql( ')' ); break; + case SqlTypes.ARRAY: + switch ( operator ) { + case DISTINCT_FROM: + appendSql( "decode(" ); + arrayToString( lhs ); + appendSql( ',' ); + arrayToString( rhs ); + appendSql( ",0,1)=1" ); + break; + case NOT_DISTINCT_FROM: + appendSql( "decode(" ); + arrayToString( lhs ); + appendSql( ',' ); + arrayToString( rhs ); + appendSql( ",0,1)=0" ); + break; + default: + arrayToString( lhs ); + appendSql( operator.sqlText() ); + arrayToString( rhs ); + } + break; default: renderComparisonEmulateDecode( lhs, operator, rhs ); break; } } + private void arrayToString(Expression expression) { + appendSql("case when "); + expression.accept( this ); + appendSql(" is not null then (select listagg(column_value||',')"); + if ( !getDialect().getVersion().isSameOrAfter( 18 ) ) { + // The within group clause became optional in 18 + appendSql(" within group(order by rownum)"); + } + appendSql("||';' from table("); + expression.accept( this ); + appendSql(")) else null end"); + } + @Override protected void renderSelectTupleComparison( List lhsExpressions, diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleNestedTableJdbcType.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleNestedTableJdbcType.java index 8460d36267..6c2d590282 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleNestedTableJdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleNestedTableJdbcType.java @@ -34,6 +34,7 @@ import java.util.Locale; import static java.sql.Types.ARRAY; import static java.util.Collections.emptySet; +import static org.hibernate.internal.util.StringHelper.truncate; import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY; /** @@ -233,8 +234,10 @@ public class OracleNestedTableJdbcType implements JdbcType { final Dialect dialect = database.getDialect(); final BasicPluralJavaType pluralJavaType = (BasicPluralJavaType) javaType; String elementTypeName = getTypeName( pluralJavaType.getElementJavaType(), dialect ); - return " nested table " + columnName - + " store as \"" + tableName + " " + columnName + " " + elementTypeName + "\""; + return " nested table " + columnName + " store as \"" + truncate( + tableName + " " + columnName + " " + elementTypeName, + dialect.getMaxIdentifierLength() + ) + "\""; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java index 77df6c199e..1a428cafb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleSqlAstTranslator.java @@ -470,7 +470,12 @@ public class OracleSqlAstTranslator extends SqlAstTrans private void arrayToString(Expression expression) { appendSql("case when "); expression.accept( this ); - appendSql(" is not null then (select listagg(column_value||',')||';' from table("); + appendSql(" is not null then (select listagg(column_value||',')"); + if ( !getDialect().getVersion().isSameOrAfter( 18 ) ) { + // The within group clause became optional in 18 + appendSql(" within group(order by rownum)"); + } + appendSql("||';' from table("); expression.accept( this ); appendSql(")) else null end"); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/refresh/RefreshAndInheritanceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/refresh/RefreshAndInheritanceTest.java index c2a716cc6f..42ce3dbdfd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/refresh/RefreshAndInheritanceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/refresh/RefreshAndInheritanceTest.java @@ -5,7 +5,6 @@ import java.util.List; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; -import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.Jpa; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -18,7 +17,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.ForeignKey; import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; @@ -47,6 +45,7 @@ public class RefreshAndInheritanceTest { scope.inTransaction( entityManager -> { ManufacturerCompany manufacturerCompany = new ManufacturerCompany(); + manufacturerCompany.setId( 1L ); manufacturerCompany.setComputerSystem( new ManufacturerComputerSystem() ); Person person = new Person(); @@ -85,7 +84,6 @@ public class RefreshAndInheritanceTest { @DiscriminatorColumn(name = "CompanyType", discriminatorType = DiscriminatorType.INTEGER) public static abstract class Company { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) protected long id; @OneToMany(mappedBy = "company", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @@ -99,6 +97,10 @@ public class RefreshAndInheritanceTest { people.add( person ); person.setCompany( this ); } + + public void setId(long id) { + this.id = id; + } } @Entity(name = "ComputerSystem") @@ -106,7 +108,7 @@ public class RefreshAndInheritanceTest { @DiscriminatorColumn(name = "CompanyType", discriminatorType = DiscriminatorType.INTEGER) public static abstract class ComputerSystem { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue private long id; @ManyToOne @@ -139,7 +141,7 @@ public class RefreshAndInheritanceTest { @Entity(name = "Person") public static class Person { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue private long id; private String firstName; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/fetch/depth/DepthOneBatchTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/fetch/depth/DepthOneBatchTest.java index 207575b545..e656b78381 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/fetch/depth/DepthOneBatchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/fetch/depth/DepthOneBatchTest.java @@ -52,7 +52,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @Setting(name = AvailableSettings.FORMAT_SQL, value = "false") } ) -@RequiresDialect(H2Dialect.class) +@RequiresDialect(value = H2Dialect.class, majorVersion = 2, comment = "H2 didn't support SQL arrays before version 2") @JiraKey("HHH-16469") public class DepthOneBatchTest { 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 0e8345589d..ff35ef52db 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 @@ -1892,8 +1892,9 @@ public class FunctionTests { } @Test - @SkipForDialect(dialectClass = OracleDialect.class) - @SkipForDialect(dialectClass = MariaDBDialect.class) + @SkipForDialect(dialectClass = OracleDialect.class, reason = "HHH-16576") + @SkipForDialect(dialectClass = MariaDBDialect.class, reason = "HHH-16576") + @SkipForDialect(dialectClass = MySQLDialect.class, majorVersion = 5, reason = "HHH-16576") public void testMaxOverUnion(SessionFactoryScope scope) { scope.inTransaction( session -> { diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/collection/EnumSet.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/collection/EnumSet.java index 8b51da1080..41cad7a420 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/collection/EnumSet.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/collection/EnumSet.java @@ -148,6 +148,6 @@ public class EnumSet extends BaseEnversJPAFunctionalTestCase { } private void verifyMapping(JdbcMapping jdbcMapping) { - assertThat( jdbcMapping.getJdbcType().getJdbcTypeCode() ).isIn( Types.VARCHAR, SqlTypes.ENUM ); + assertThat( jdbcMapping.getJdbcType().getJdbcTypeCode() ).isIn( Types.VARCHAR, Types.NVARCHAR, SqlTypes.ENUM ); } }