Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Globally map boolean fields onto smallint in Postgres
Globally map boolean fields onto smallint in Postgres [message #1863067] Sat, 13 January 2024 22:06 Go to next message
Alexander Roytman is currently offline Alexander RoytmanFriend
Messages: 6
Registered: March 2018
Junior Member
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
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.


I can, of course, use converters but I do not want to explicitly annotate every boolean field (and useautoApply = true on 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
Re: Globally map boolean fields onto smallint in Postgres [message #1863106 is a reply to message #1863067] Tue, 16 January 2024 18:33 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 54
Registered: December 2021
Member
JPA specification itself provides the @Convert annotation with an example that allows you to turn boolean into Int regardless of the database:

@Convert(converter=BooleanToIntegerConverter.class)
boolean fullTime;

The boolean type though is held within PostgreSQLPlatform, but I don't recall if this will only handle DDL and if you still need some other mapping to have it convert Integer<->boolean internally - if so, it would also be in the PostgreSQLPlatform method, overriding the type conversion methods of DatabasePlatform.

Best of luck,
Chris
Previous Topic:Deletion of entity throwing foreign key constraint for unidirectional mapping
Next Topic:Enabling weaving - problems and advice on migration
Goto Forum:
  


Current Time: Sat Apr 27 20:14:52 GMT 2024

Powered by FUDForum. Page generated in 0.03341 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top