How to globally map boolean fields onto smallint in Eclipeselink on postgres

29 Views Asked by At

Hello I was trying to configure eclipselink to save boolean fields to smallint We are migrating from oracle where booleans were mapped onto number(1) and would like to retain numeric value to prevent potential breakage of related (non jpa) systems consuming our tables directly.

Updating any boolean field results in

[code]
Caused by: org.postgresql.util.PSQLException: ERROR: column "is_active" is of type smallint but expression is of type boolean
  Hint: You will need to rewrite or cast the expression.
[/code]

I can, of course, use eclipselink converters but I do not want to explicitly annotate every boolean field (and useautoApply = true on a such a common type as boolean field - i guess I could but it is rather all inclusive and also may have some performance implication ).

So I was looking for a way to tweak Postgres platform class but could not identify any point where I can do it

I looked into PostgreSQLPlatform and its superclasses and also was trying to trace where I can do it in other classes. It does not look like eclipselink consults platform classes for direct mapping fields. it also does not appear that when handling boolean fields eclipselink chacks JDBC Type at all to alter its behavior (would have been nice when writing/reading boolean to a row/parameter to check its JDBC type and do basic conversion to 0/1

Any suggestions would be greatly appreciated

Thank you, Alex

spent hours with debugger trying to figure out where field value is converted to row/parameter value and why no check on field metadata JDBC type is being made to support basic type conversion such as boolean and int or bit

0

There are 0 best solutions below