Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ protected Object[] getArray(
}

protected <X> X getArray(BasicExtractor<X> extractor, java.sql.Array array, WrapperOptions options) throws SQLException {
if ( array != null && getElementJdbcType() instanceof AggregateJdbcType ) {
final AggregateJdbcType aggregateJdbcType = (AggregateJdbcType) getElementJdbcType();
final JdbcType jdbcType = getElementJdbcType();
if (array != null
&& jdbcType instanceof AggregateJdbcType
&& ((AggregateJdbcType) jdbcType).getEmbeddableMappingType() != null) {
final AggregateJdbcType aggregateJdbcType = (AggregateJdbcType) jdbcType;
final EmbeddableMappingType embeddableMappingType = aggregateJdbcType.getEmbeddableMappingType();
final Object rawArray = array.getArray();
final Object[] domainObjects = new Object[Array.getLength( rawArray )];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.function.array;

import java.util.Arrays;
import java.util.List;

import org.hibernate.boot.ResourceStreamLocator;
Expand All @@ -14,12 +13,14 @@
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.dialect.OracleArrayJdbcType;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SpannerDialect;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.query.criteria.JpaRoot;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.java.ArrayJavaType;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
Expand All @@ -37,6 +38,7 @@
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.hibernate.testing.orm.junit.Jira;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -172,4 +174,21 @@ public void testNonExistingArrayType(SessionFactoryScope scope) {
} );
}

@Test
@Jira("https://hibernate.atlassian.net/browse/HHH-19681")
@RequiresDialect(PostgreSQLDialect.class)
public void testJsonBJdbcArray(SessionFactoryScope scope) {
scope.inTransaction( session -> {
String sql = "select groupId, array_agg(json_values) " +
"from (VALUES (1,'[1,2]'::jsonb),(1,'[10,20]'::jsonb)) as row(groupId,json_values) " +
"group by groupId";

List<Object[]> result = session.createNativeQuery(sql, Object[].class).getResultList();
assertEquals(1,result.size());
assertEquals(2, result.get(0).length);
assertEquals( 1,result.get(0)[0] );
assertEquals( "[[1, 2], [10, 20]]", Arrays.toString((String[])result.get(0)[1]) );
} );
}

}
Loading