From 62b6ed5caec8922a7e03258ef5a2c1e1051c3bd8 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Fri, 25 Oct 2024 22:13:47 +0200 Subject: [PATCH] HHH-18765 - Add test for issue Signed-off-by: Jan Schatteman --- .../test/type/BooleanArrayToStringTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayToStringTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayToStringTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayToStringTest.java new file mode 100644 index 0000000000..db6ba058e9 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BooleanArrayToStringTest.java @@ -0,0 +1,64 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.type; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import org.hibernate.dialect.OracleDialect; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.Jira; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; +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.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @author Jan Schatteman + */ +@DomainModel ( + annotatedClasses = {BooleanArrayToStringTest.TestEntity.class} +) +@SessionFactory +public class BooleanArrayToStringTest { + + @Test + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsTypedArrays.class) + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsArrayToString.class) + @SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required") + @Jira( value = "https://hibernate.atlassian.net/browse/HHH-18765" ) + public void testBooleanArrayToStringFunction(SessionFactoryScope scope) { + scope.inTransaction( + session -> session.persist( new TestEntity(1L, new Boolean[]{Boolean.FALSE, Boolean.FALSE, null, Boolean.TRUE}) ) + ); + scope.inTransaction( + session -> { + String s = session.createQuery( "select array_to_string(t.theBoolean, ';', 'null') " + + "from TestEntity t", String.class ).getSingleResult(); + Assertions.assertEquals("false;false;null;true", s); + } + ); + scope.inTransaction( + session -> session.createMutationQuery( "delete from TestEntity" ).executeUpdate() + ); + } + + @Entity(name = "TestEntity") + public static class TestEntity { + @Id + private Long id; + private Boolean[] theBoolean; + + public TestEntity() { + } + + public TestEntity(Long id, Boolean[] theBoolean) { + this.id = id; + this.theBoolean = theBoolean; + } + } +}