vladmihalcea/hypersistence-utils
StringArrayType.INSTANCE is not working with a two dimensional String array parameter on PostgreSQL
オープン
#436 opened on 2022/05/10
good first issuerequires test case
Repository metrics
- Stars
- (2,666 個のスター)
- PR merge metrics
- (平均マージ 9d 17h) (30d で 1 merged PR)
説明
Hibernate ORM core version: 5.6.8.Final Hibernate Types 55 version: 2.16.2
StringArrayType is expected to work with multidimensional arrays based on the Javadoc, but that isn't the case when used with Hibernate native query parameters and PostgreSQL.
One dimensional array parameter is working as expected:
public Customer findWithOneDimensionalArrayParameter() {
return (Customer) entityManager
.createNativeQuery(
"SELECT 1 AS id, 'foo' AS first_name, 'bar' AS last_name WHERE :param = ARRAY['foo'];",
Customer.class
)
.unwrap(Query.class)
.setParameter("param", new String[] {"foo"}, StringArrayType.INSTANCE)
.getSingleResult();
}
But two dimensional array parameter isn't working:
public Customer findWithTwoDimensionalArrayParameter() {
return (Customer) entityManager
.createNativeQuery(
"SELECT 1 AS id, 'foo' AS first_name, 'bar' AS last_name WHERE :param = ARRAY[ARRAY['foo'], ARRAY['bar']];",
Customer.class
)
.unwrap(Query.class)
.setParameter("param", new String[][] {new String[] {"foo"}, new String[] {"bar"}}, StringArrayType.INSTANCE)
.getSingleResult();
}
The Exception:
java.lang.IllegalArgumentException: Array-valued parameter value element [[Ljava.lang.String;@f10d055] did not match expected type [[Ljava.lang.String; (n/a)]
Demo: demo.zip
Thanks having a look.