Hibernate HSQLDB ARRAY Type

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!


As previously explained, although Hibernate does not support database ARRAY column types by default, you can easily implement a custom Hibernate ArrayType. While the previous solution worked on PostgreSQL, in this article, you are going to see that it is fairly easy to adapt it to HSQLDB.

Domain Model

Assuming we have the following Event entity in our system:

We need a way to persist the String[] and Integer[] entity attributes since Hibernate, by default, does not support database-specific ARRAY types.

For that, we are going to use two custom Hibernate types:

@Entity(name = "Event")
@Table(name = "event")
        name = "string-array", 
        typeClass = VarCharStringArrayType.class
        name = "int-array", 
        typeClass = IntArrayType.class
public class Event {

    private Long id;

    @Type(type = "string-array")
        name = "sensor_names", 
        columnDefinition = "VARCHAR(100) ARRAY"
    private String[] sensorNames;

    @Type(type = "int-array")
        name = "sensor_values", 
        columnDefinition = "INT ARRAY"
    private Integer[] sensorValues;

    //Getters and setters omitted for brevity

The code for StringArrayType and IntArrayType has been described before in this article so we are not going to repeat it here.

The only difference is that we are using the VarCharStringArrayType now since HSQLDB does not support the TEXT database column type:

public class VarCharStringArrayType
        extends StringArrayType {

    public static final VarCharStringArrayType INSTANCE = 
        new VarCharStringArrayType();

    public VarCharStringArrayType() {

Also the VarCharStringArrayTypeDescriptor is rather trivial too:

public class VarCharStringArrayTypeDescriptor
        extends StringArrayTypeDescriptor {

    public static final VarCharStringArrayTypeDescriptor INSTANCE = 
            new VarCharStringArrayTypeDescriptor();

    public String getSqlArrayType() {
        return "varchar";

And, that’s it!

You don't have to create all these types manually. You can simply get them via Maven Central using the following dependency:


For more info, check out the hibernate-types open-source project.

Testing time

When persisting two Event entities:

Event nullEvent = new Event();


Event event = new Event();
    new String[]{"Temperature", "Pressure"}
    new Integer[]{12, 756}


Hibernate is going to execute the following SQL INSERT statements:



When fetching the Event entity:

Event event = entityManager.find(Event.class, 1L);

assertArrayEquals(new String[]{"Temperature", "Pressure"}, event.getSensorNames());
assertArrayEquals(new Integer[]{12, 756}, event.getSensorValues());

Hibernate can properly map the underlying ARRAY column type to the String[] and Integer[] Java arrays.

You can also use JPQL to filter the results based on a given Java array:

Event event = entityManager
    "select e " +
    "from Event e " +
    "where e.sensorNames = :sensorNames", Event.class)
    new String[]{"Temperature", "Pressure"}

If you enjoyed this article, I bet you are going to love my Book and Video Courses as well.


As demonstrated in this article, mapping ARRAY columns types to Java String[] or Integer arrays is fairly easy when using Hibernate.

Newsletter logo
10 000 readers have found this blog worth following!

If you subscribe to my newsletter, you'll get:
  • A free sample of my Video Course about running Integration tests at warp-speed using Docker and tmpfs
  • 3 chapters from my book, High-Performance Java Persistence,
  • a 10% discount coupon for my book.

6 Comments on “Hibernate HSQLDB ARRAY Type

  1. javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Could not set field value [[Ljava.lang.Object;@56781d96] value by reflection : [class com.guinevisitaturistica.guinevisitabackend.dto.Hotel.code] setter of com.guinevisitaturistica.guinevisitabackend.dto.Hotel.code

    Hi sir how are you I am having some uses with Listing my records in database, the field CODE wich is array of string throws an error javax.persistence.PersistenceException when I try to test the List method.

    • I’m fine, thanks. Check out my consulting page if you are interested in hiring me to help you with your issue.

      • thank you sir for answer me as fast as you can, actually I am working on my school project so I really need help for this, please I need to find the solution .

      • All the best then. Study my blog and you will learn more.

  2. Hi

    I am trying to pass string array as input to the DB2 Stored procedure with above mentioned dependency(“hibernate-types-52”). But i am facing issue while setting up the input parameter as below.

    StoredProcedureQuery.setParameter(“Input_Array”, new TypedParameterValue(new StringArrayType(),new String[] {“data”});

    • The ARRAY support was tested on PostgreSQL. I never used DB2. You could contribute the Db2ArrayType if you want.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.