error using postgres UUID primary key with Hibernate
|Added at||2016-12-14 19:12|
I am developing a greenfield web app that uses Spring boot 1.4.1 - which uses spring 4.3.3 & Hibernate 5.2.3.Final under the hood.
We are using Postgres 9.4 for our database, so I have the postgres-9.4.1212.jar in my class path as well.
All my tables use primary (& foreign) keys of type UUID. In my entity class itself, I have the following annotations over the id property:
When we connect to the database using this url and do a query
We get the following error
The error goes away and the query works fine when we change the connection url to the following:
Note the added suffix: ?stringtype=unspecified
Is this the right thing to do? Is there a better way to fix the error?
Saw a few stack-overflow posts related to using postgres UUID in hibernate, so it looks like other folks are having the same issue as well. None of the answers seem satisfactory. It is odd that this would not work out of the box.
After perusing Hibernate 5.2.3 documentation and R-ing TFM, I see this snippet which seems like it may be related:
Quoting from the above link
Also elsewhwere in section 2.3.13 in the above document, it also says this
I suspect I need to create an @Bean to tell Spring-boot to configure the MetadataBuilder, but am not quite sure how to do this.
Looking for some insights on how to configure hibernate's MetadataBuilder to process UUID as char instead of binary.