We use Postgres jsonb_agg function in criteria query API like this:
cb.function(
JSONB_AGG_FUNCTION_NAME,
JsonNode.class,
someJoin.get(someField)
)
and map a result into projection with constructor:
Projection (<some args>, com.fasterxml.jackson.databind.JsonNode node)
In Hibernate 5 we registered jsonb_agg function using this approach:
public class ExtendedPgDialect extends PostgreSQLDialect {
public static final String JSONB_AGG_FUNCTION_NAME = "jsonb_agg";
public ExtendedPgDialect() {
registerFunction(JSONB_AGG_FUNCTION_NAME,
new StandardSQLFunction(JSONB_AGG_FUNCTION_NAME, JsonNodeBinaryType.INSTANCE));
}
}
But in Hibernate 6.6.33.Final we can't register that function and can't use it for querying data.
Also we used (JsonNodeBinaryType) type from io.hypersistence:hypersistence-utils-hibernate-53 library. How to register jsonb_agg function in Hibernate 6 for mapping to JsonNode java type?