I am implementing a synchronize solution between DB nodes : Oracle vs Postgres. Same J2EE web application will run on those 2 databases and a background process will synch those database with each other.
. One problem is Oracle stores boolean Hibernate mapping value as 1 or 0. In contrast, Postgres stores Hibernate boolean as 'y' or 'n' which is very annoying and troublesome when doing DB synch. So I would like to force Postgres to map Hibernate boolean type to numeric/integer/smallint by trying to implement a custom Dialect extends from PostgreSQLDialect. I tried to override
public String toBooleanValueString(boolean bool)
and register type mappings as well. But , sadly, after many trials , it seems that it does not work.
At the end, I needed to use the ugly solution by adding :
@Type(type="org.hibernate.type.NumericBooleanType")
to all boolean attributes in my mapped class. It is ugly because it adds dependency to Hibernate in my Model Project. However, I can live with it for now.
You may try to add columnDefinition="smallint" of JPA to mapped boolean atribute instead of using ugly @Type. However, to me, for several reasons, it is not an option.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment