Reputation:
I've bar-code filed in a database table that is UNIQUE
.
But field is not mandatory so I want to keep it empty.
I tried put null
but it is bad idea to do.
Cause
I'm using Hibernate
so hibernate.hbm.xml doesn't generate wrapper class Integer that could be :
<property name="barcode" type="java.lang.Integer">
<column name="barcode" />
So above expression allow null
insertion.
Instead it generate UNIQUE
field as follow :
<property name="barcode" type="java.lang.Integer">
<column name="barcode" unique="true" />
But I have make barcode
in database table UNIQUE
and nullable
.
That don't help anyway.
So how can I keep it empty or other way around to deal with it.
Upvotes: 1
Views: 33
Reputation: 74
null
indicates the lack of data. It is perfectly reasonable to use null
in a UNIQUE
column as long as long as the column is not also set as NOT NULL
.
Upvotes: 1