Mapping array with Hibernate

后端 未结 4 814
谎友^
谎友^ 2020-11-29 09:53

Can you please help me to map this class using Hibernate?

public class MyClass{
    private Long id;
    private String name;
    private int[] values;
    .         


        
4条回答
  •  攒了一身酷
    2020-11-29 10:24

    Hibernate (and JPA) can't directly map the PostgreSQL array type. See this question for how to proceed if you really need to retain your database structure as it is. This thread has an example of the required custom type.

    If you can change your schema, you can let hibernate create an additional table to handle the collection - List. Then, depending on the version of hibernate you are using:

    • JPA 2.0 compliant - use @ElementCollection
    • JPA 1.0 compliant - use @CollectionOfElements

提交回复
热议问题