Search code examples
javaspringkotlinjpaspring-data-jpa

How to map array database type to kotlin


I have this entity

@Entity
@Table(name = "foo")
class Foo(
    @Column(name = "bar_ids", columnDefinition = "uuid[]")
    val barIds: Array<UUID>,
) {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long = 0
}

which gives me

'Basic' attribute type should not be 'UUID[]'

How to define an array datatype?


Solution

  • I think, this is the way to go

    
    import io.hypersistence.utils.hibernate.type.array.EnumArrayType
    import io.hypersistence.utils.hibernate.type.array.internal.AbstractArrayType
    
    @Type(
          value = EnumArrayType::class,
          parameters = [Parameter(name = AbstractArrayType.SQL_ARRAY_TYPE, value = "uuid")]
        )
        @Column(name = "bar_ids", columnDefinition = "uuid[]")
        val barIds: List<UUID>,