I want to use PostgreSQL's native UUID type with a Java UUID. I am using Hibernate as my JPA provider and ORM. If I try to save it directly, it is just saved as a bytea in Postgres.
How can I do this?
![]() ![]() ![]() |
I want to use PostgreSQL's native UUID type with a Java UUID. I am using Hibernate as my JPA provider and ORM. If I try to save it directly, it is just saved as a bytea in Postgres. How can I do this?
|
|||
|
![]() ![]() ![]() |
Try use the latest development version of the JDBC driver (Currently 8.4dev-700), or wait for the next release version. (Edited to add: 8.4-701 has been released) The release notes mention this change:
|
|||
|
![]() ![]() |
In non-JPA usage I'd create a UserType to format the UUID as a string that PostgreSQL accepts, then just give the name of the UserType implementation as the column type. |
||
|
![]() ![]() |
you could try with:
where columnDefinition is a fragment of native SQL |
||
|
![]() ![]() |
Perhaps you can get UUID type to be auto-converted to a String (uuid.toString() should give the canonical 36-char representation)? DBs usually convert things reliably between Strings and native types. |
||
|