Can Hibernate 3.6 persist a field as NULL if the value matches some default?

195 Views Asked by At

I have many entities with several Enum and Boolean fields. In order to make these objects safe to work with in code, the fields use default values and are never NULL (as a policy). However, in the database, the large majority are stored with defaults present.

On PostgreSQL 9.3, storage of NULL values is (nearly) free in terms of space. I want to take advantage of this by persisting entities with default values as NULL. I'm willing to make the trade-off that my database queries will become slightly more complex as a result.

In Hibernate 3.6, is it possible to annotate, or otherwise configure, my fields to persist as NULL when the default value is used?

0

There are 0 best solutions below