I've been pulling my hair out all day on this problem and am severely in need of help here. I cannot figure out how to get Hibernate to assign default values to columns when it creates objects. I have searched and found many ideas and leads, but all of them have turned out to be dead ends.
Let's use this simplified table as an example:
CREATE TABLE fred
(
waldo boolean DEFAULT false
);
When I use Hibernate tools to reverse-engineer a database schema, there is no sign of the default value in the resulting mapping document. (Which, to me, is either a bug or a missing feature, but that's ancillary to the main question.)
After spending a few hours trying to figure this out and getting nowhere, I decide to edit the mapping document manually. I sacrifice automation, but I solve the immediate problem. So the property definition now looks like this:
<property name="waldo" type="java.lang.Boolean">
<column name="waldo" default="false" />
</property>
That doesn't work either; if I create an instance of Fred in the code, the waldo field stubbornly remains null.
I spent a few more hours investigating this, finding several dead ends. Eventually I run across the hackish solution described here:
http://forum.hibernate.org/viewtopic.ph ... 54#2362554
I added postProcessConfiguration to my code and traced through it as the database starts up, verifying that "false" is assigned as the column's default value.
And when I create a Fred, the waldo field
still remains null!!
So I am in serious need of some expert advice to tell me what the hell is going on. I have spent a frustrating 10+ hours on this one single problem on a project that is already behind schedule. Your help is greatly appreciated.
Hibernate version: 3.2.6
Database version: PostgreSQL 8.3