如何在JPA中映射整数数组 [英] How to map an integer array in JPA

查看:546
本文介绍了如何在JPA中映射整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将spring jpa与hibernate和postgres一起使用

I use spring jpa with hibernate and postgres

在一个实体中,我尝试使用List和integer []

In an entity, I tried to use a List and integer[]

在数据库中,我有一列类型:

In the database, I have a column of type:

integer[] 

有什么JPA方式可以使用它吗?

is there any jpa way to use it?

推荐答案

JPA无法直接将数组持久化到单独的表或数据库数组(例如,映射到java.sql.Array的数组).因此,您有两种方法:

JPA is not able to persist arrays to a separate table or database array (e.g. ones mapped to java.sql.Array) out of the box. So you have two ways:

1)使用@Lob将此列另存为BLOB或CLOB

1) Use @Lob to save this column as BLOB or CLOB

@Lob
private Integer[] values;

2)使用List<Integer>代替数组

@ElementCollection
public List<Integer> values;

这篇关于如何在JPA中映射整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆