Map Postgresql text[] field

Hi there,
I am trying to map a table field which in postgres has a column definition set to text[].

Tried messing around with converters, ( got them to work for jsonb) , but not with text arrays.

Getting this exception:
java.lang.ClassCastException: class [Ljava.lang.String; cannot be cast to class org.postgresql.util.PGobject ([Ljava.lang.String; is in module java.base of loader ‘bootstrap’; org.postgresql.util.PGobject is in unnamed module of loader ‘app’)
at it.topcs.controlroom.entity.TextArrayConverter.convertToEntityAttribute(TextArrayConverter.java:11)

In entity class this is how the column is defined:
@Converter(name = “TextArrayConverter”, converterClass = TextArrayConverter.class)
@Convert(converter = TextArrayConverter.class)
@Column(name = “days_of_week_ranges”,columnDefinition = “text[]”)
private String daysOfWeekRanges;

Attached is the converter class
TextArrayConverter.java (865 Bytes)

I am probably doing something wrong, but have no clue. Can you help ?

Hi Andrea,

You convertor assumes that the attribute type is String[], while the actual attribute type is String.
How do you want to represent the array in the entity attribute? As a comma-separated list?

Yes, that would be optimal

Then you should parameterize your converter differently:

... implements AttributeConverter<String, PGobject>

Hi, I solved this way.
Thanks
TextArrayConverter.java (1.1 KB)