I'm using Spring Boot 1.4.1, which includes Hibernate 5, with Postgres 9.6, and I'm trying to create an entity with a UUID ID but using Postgres' UUID generation instead of Hibernate's. Many similar questions say to set the column type as pg-uuid
. That seems to work for non-database-generated ID columns, but when I try to use it for the ID column I get
org.hibernate.id.IdentifierGenerationException: unrecognized id type : pg-uuid -> java.util.UUID
So it looks like Hibernate is applying the type correctly, but not converting it.
Here is how the ID column of my entity is setup:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@org.hibernate.annotations.Type(type="pg-uuid")
private UUID id;
And the table is setup similar to as follows (uuid-ossp
is installed)
create table example (
id UUID NOT NULL DEFAULT uuid_generate_v1mc(),
...
);
I would prefer to have the database generate the UUIDs and don't want to use Hibernate's generation strategies. Is there a way to get this to work?