JPA 2.1 provides a very easy way to use the PostgreSQL uuid column type and
java.util.UUID
as the type of the corresponding entity field:@javax.persistence.Converter(autoApply = true)
public class PostgresUuidConverter implements AttributeConverter<UUID, UUID> {
@Override
public UUID convertToDatabaseColumn(UUID attribute) {
return attribute;
}
@Override
public UUID convertToEntityAttribute(UUID dbData) {
return dbData;
}
}
Just add this class to your persistence configuration and annotate UUID fields with
@Column(columnDefinition="uuid")
.
Not a correct solution. Results in exception at runtime, 'expression is of type bytea[], requires UUID'...
ReplyDeleteThis simple 'solution' is all over the net, and is misleading.
I agree with SleepsOnGrates. I get the same error.
ReplyDelete