skip to Main Content

I am using the latest hibernate version (6.5) and hypersistence utils in this version is not supporting custom array types as it’s natively supported by hibernate > 6.4.

I’ve tested and this works natively for float[] arrays, so e.g. this works

@Entity
public class MyEntity {
    float[] myArray
}

but if I do the same for a 2d array:

float[][] myArray

I get this error:

Caused by: java.lang.ClassCastException:
class org.hibernate.type.internal.BasicTypeImpl cannot be cast to class org.hibernate.type.BasicPluralType (org.hibernate.type.internal.BasicTypeImpl and org.hibernate.type.BasicPluralType are in unnamed module of loader ‘app’)

So it seems mapping the column as json and using columnDefinition = "jsonb" seems to be only solution. Is there another way to map multidimensional arrays natively supported by hibernate 6.5?

2

Answers


  1. Consider using a custom type definition using the built-in FloatPrimitiveArrayJavaType

    @Type(value = FloatPrimitiveArrayJavaType.class, parameters = @Parameter(name = "sql_array_type", value = "float_array"))
    @Column(name = "2d_float_array", columnDefinition = "float_array[][]")
    private float[][] myArray;
    
    Login or Signup to reply.
  2. Hypersistence-Utils and PostgreSQL support the use of multi-dimensional arrays.

    @Type(value = FloatArrayType.class)
    @Column(name = "data", columnDefinition = "real[][]")
    private float[][] data;
    

    Tested using

    org.hibernate.orm:hibernate-core:6.5.3.Final
    io.hypersistence:hypersistence-utils-hibernate-63:3.8.3
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search