2

I execute this request @Subselect using Hibernate

SELECT сolumn1, array_agg(DISTINCT сolumn2::integer) FROM table GROUP BY сolumn1;

result SQL:

 сolumn1 | сolumn2 
------------+---------------------
          1 | {1}                 
          2 | {2,3}               
          3 | {3}  

           

My DAO class:

enter image description here

import lombok.Data;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Subselect;


import javax.persistence.*;

@Data
@Entity
@Subselect("SELECT сolumn1,\n" +
        "\tarray_agg(DISTINCT сolumn2::integer)\n" +
        "FROM table GROUP BY сolumn1;")
@Immutable
public class Table {

    @Id
    @Column(name = "сolumn1")
    private Long сolumn1;

    @Column(name = "сolumn2")
    private Integer[] сolumn2;
}

Now it does not work, an error occurs:

message": "org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize

How mapping List with array_agg ?

1 Answers1

0

There's a problem with deserialization of your Interger[] column2 . Replace it with a Collection<Integer>

That should allow it to map succesfully.

Mapping array with Hibernate

Akin Okegbile
  • 1,108
  • 19
  • 36