Skip to content

Cepr0/hibernate-types-in-projection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

An attempt to use json/array types of hibernate-types in Spring Data projections

Projection:

public interface ParentProjection { String getName(); List<String> getChildNames(); }

Query:

@Query(value = "" + "select " + " p.name as name, " + " array_agg(c.name) as childNames " + "from " + " parents p " + " join children c on c.parent_id = p.id " + "where " + " p.id = ?1 " + "group by " + " p.name" + "", nativeQuery = true) Optional<ParentProjection> getParentWithChildNamesAsArray(Integer id);

Custom Postgres dialect:

public class PostgreSQLCustomDialect extends PostgreSQL95Dialect { public PostgreSQLCustomDialect() { super(); registerHibernateType(Types.OTHER, JsonNodeStringType.class.getName()); registerHibernateType(Types.ARRAY, StringArrayType.class.getName());	} }

When PostgreSQL aggregate function array_agg is used in the query above, then the following exception is raised:

org.springframework.orm.jpa.JpaSystemException: Could not instantiate Type: com.vladmihalcea.hibernate.type.array.StringArrayType; 

If json_agg function is used, then we have another exception:

java.lang.IllegalArgumentException: Projection type must be an interface! 

About

Bad attempt to use json or array types of hibernate-types lib in Spring Data projections

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages