|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.orm.test.type; |
| 6 | + |
| 7 | +import jakarta.persistence.Entity; |
| 8 | +import jakarta.persistence.Id; |
| 9 | +import org.hibernate.dialect.OracleDialect; |
| 10 | +import org.hibernate.testing.orm.junit.DialectFeatureChecks; |
| 11 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 12 | +import org.hibernate.testing.orm.junit.Jira; |
| 13 | +import org.hibernate.testing.orm.junit.RequiresDialectFeature; |
| 14 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 15 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 16 | +import org.hibernate.testing.orm.junit.SkipForDialect; |
| 17 | +import org.junit.jupiter.api.Assertions; |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +/** |
| 21 | + * @author Jan Schatteman |
| 22 | + */ |
| 23 | +@DomainModel ( |
| 24 | + annotatedClasses = {BooleanArrayToStringTest.TestEntity.class} |
| 25 | +) |
| 26 | +@SessionFactory |
| 27 | +public class BooleanArrayToStringTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsTypedArrays.class) |
| 31 | + @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsArrayToString.class) |
| 32 | + @SkipForDialect( dialectClass = OracleDialect.class, reason = "External driver fix required") |
| 33 | + @Jira( value = "https://hibernate.atlassian.net/browse/HHH-18765" ) |
| 34 | + public void testBooleanArrayToStringFunction(SessionFactoryScope scope) { |
| 35 | + scope.inTransaction( |
| 36 | + session -> session.persist( new TestEntity(1L, new Boolean[]{Boolean.FALSE, Boolean.FALSE, null, Boolean.TRUE}) ) |
| 37 | + ); |
| 38 | + scope.inTransaction( |
| 39 | + session -> { |
| 40 | + String s = session.createQuery( "select array_to_string(t.theBoolean, ';', 'null') " |
| 41 | + + "from TestEntity t", String.class ).getSingleResult(); |
| 42 | + Assertions.assertEquals("false;false;null;true", s); |
| 43 | + } |
| 44 | + ); |
| 45 | + scope.inTransaction( |
| 46 | + session -> session.createMutationQuery( "delete from TestEntity" ).executeUpdate() |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + @Entity(name = "TestEntity") |
| 51 | + public static class TestEntity { |
| 52 | + @Id |
| 53 | + private Long id; |
| 54 | + private Boolean[] theBoolean; |
| 55 | + |
| 56 | + public TestEntity() { |
| 57 | + } |
| 58 | + |
| 59 | + public TestEntity(Long id, Boolean[] theBoolean) { |
| 60 | + this.id = id; |
| 61 | + this.theBoolean = theBoolean; |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments