askullhead askullhead - 1 month ago 5
Java Question

Configure hibernate (using JPA) to store Y/N for type Boolean instead of 0/1

Can I setup JPA/hibernate to persist

Boolean
types as
Y/N
? In the database (the column is defined as
varchar2(1)
. It currently stores them as
0/1
. The database is Oracle.

Answer

The only way I've figured out how to do this is to have two properties for my class. One as the boolean for the programming API which is not included in the mapping. It's getter and setter reference a private char variable which is Y/N. I then have another protected property which is included in the hibernate mapping and it's getters and setters reference the private char variable directly.