'Hibernate & Postgres: Default value provided for Not-NULL Column: Error: not-null property references a null or transient value
We have an HBM-based Hibernate Spring project linking to a Postgres DB. Two Not-NULL columns are defined as follows with defaults, with corresponding DB constraints and defaults as well:
HBM:
<property name="biasFlag" type="yes_no">
<column name="BIAS_FLAG" length="1" not-null="true" default="N"/>
</property>
<property name="clinicalTrialFlag" type="yes_no">
<column name="CLINICAL_TRIAL_FLAG" length="1" not-null="true" default="N"/>
</property>
DB (Postgres):
bias_flag character varying(1) COLLATE pg_catalog."default" NOT NULL DEFAULT 'N'::text,
clinical_trial_flag character varying(1) COLLATE pg_catalog."default" NOT NULL DEFAULT 'N'::text,
But when we don't specify these fields in the domain object in the Spring app, Hibernate complains:
org.hibernate.PropertyValueException: not-null property references a null or transient value :
Request.biasFlag at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:106) at
The whole point is to have a "silent default" (this was added later) so that the code doesn't choke. Anyone know what's going on? Is there some Postgres Driver bug not applying the DEFAULT properly?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
