Search code examples
databasepostgresqlhibernatejpauuid

UUID[] in hibernate not mapping


My question is similar to Postgresql UUID supported by Hibernate? but I have to use array of UUID. I receive the error

Caused by: org.postgresql.util.PSQLException: ERROR: column "system_ids" is of type uuid[] but expression is of type bytea

Column definition is

@Column(name = "system_ids", columnDefinition = "uuid[]")
private UUID[] system_ids;

I am using Postgresql so I have mapped other UUID pk's as

@Type(type = "pg-uuid")

I do not know how to map UUID[]


Solution

  • I found out the solution. I am using hibernate 4.3.11.Final due to some issues and couldn't use the typedef class UUIDArrayType.class so I imported the dependency in pom.xml

        <dependency>
            <groupId>com.vladmihalcea</groupId>
            <artifactId>hibernate-types-5</artifactId>
            <version>2.9.13</version>
        </dependency>
    

    Now my code looks like this

    ...
    
    @TypeDefs({
            @TypeDef(name = "uuid-array", typeClass = UUIDArrayType.class) })
    ...
    
        @Type(type = "uuid-array")
        @Column(name = "system_ids", columnDefinition = "uuid[]")
        private UUID[] system_ids;
    
    ...