7

I use spring jpa with hibernate and postgres

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

In the database, I have a column of type:

integer[] 

is there any jpa way to use it?

3 Answers 3

12

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) Use @Lob to save this column as BLOB or CLOB

@Lob
private Integer[] values;

2) Use List<Integer> instead of an array

@ElementCollection
public List<Integer> values;
Sign up to request clarification or add additional context in comments.

Comments

1

Just doing this worked fine for me:

@Column(name="column_name")
private Integer[] columnName;

I didn't need @Lob like Mykola Yashchenko suggested.

Comments

0

You can also write your custom generic array converter to resolve this issue.

1 Comment

Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.