I am trying to use UUID as the primary key of my table. I am using postgresql for production and h2 for test. I am creating the table using liquibase and set this column type as UUID, which liquibase support the type for both h2 and postgres
<column name="uuid" type="UUID">
@Id
private UUID uuid;
I got to two questions/issues when I try to save a record using JPA with spring-boot. For Postgres, I will get the following error
org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
I understand this was because JPA doesn't know which type should be converted to from Java UUID type. Some people suggest using @Type(type="org.hibernate.type.PostgresUUIDType") on the UUID filed in the entity class. However, this doesn't change anything for me and I still got the same error. Not sure what I have missed.
A further question is how to make it also working with h2 when I switch to run the test config, as the annotation is specific to the Postgres. Any suggestion please?
question from:
https://stackoverflow.com/questions/66051135/uuid-support-for-different-db-with-spring-boot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…