Hello,
I using PostgreSQL 9.2 and UUID native type. I am using Hibernate 4 and has some entities using java.util.UUID type.
I expected automatic mapping, zero worries (it worked very well on H2) ... but i get problems since Hibernate try to save a bytea where db expect uuid.
Then i started to search ... and i get the solution of annotate explicitly the field to use pg-uuid type. sadly this solution does not fits to me ... i cannot do that since i will broke compatibility with other databases.
So i need to do something else ... i figure: 1. Extend postgresql dialect or 2. Define a custom type that switches the mapping depending on environment variables as here -> https://zorq.net/b/2012/04/21/switching-hibernates-uuid-type-mapping-per-database/
I prefer 1 ... and it seems easier so i tried do this:
public class PostgreSqlCustomDialect extends org.hibernate.dialect.PostgreSQLDialect { public PostgreSqlCustomDialect() { super(); registerColumnType(Types.OTHER, "uuid"); registerHibernateType(Types.OTHER, "org.hibernate.type.PostgresUUIDType"); } }
... but i get the same problem! ... did i made something wrong??
I've also read Hibernate documentation section 6.5 where i see: "To register a new type or to override an existing type registration, applications would make use of the registerTypeOverride method of the org.hibernate.cfg.Configuration class when bootstrapping Hibernate."
Sounds very good ... but i need additional hints on how to achieve this :P
Could someone, please, help me?
Thanks in advance.
|