hibernate 如何在JPA中表示整数数组

p8h8hvxi  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(76)

如何使用JPA在java @Entity类中表示integer ARRAY的列定义,是否有本机Map,或者我们应该为此定义columnDefinition

https://www.postgresql.org/docs/current/arrays.html
scores integer ARRAY,

字符串

jv2fixgn

jv2fixgn1#

在java和spring的原生环境下,做和管理整个过程可能非常棘手,它是使用@ElementCollection完成的。
然而,使用Vlad Mihalcea的Hypersistence Utils库使其相对简单和直接。
将库的适当的maven依赖项添加到项目中。

@Entity
@Table(name = "my_entity")
@TypeDef(name = "int-array", typeClass = IntArrayType.class) // declaring the type
public class MyEntity{

    @Type(type = "int-array") // using the declared type
    @Column(
        name = "scores",
        columnDefinition = "integer[]"
    )
    private int[] scores;
}

字符串
关于library的更多信息。一个article来帮助类型Map。

相关问题