Java.sql.sqlexception: Field 'supplier_id' Doesn't Have A Default Value
Solution 1:
The error is self explanatory. Your column supplier_id does not have a default value. So during insertion, mysql cannot figure out what to insert in the column supplier_id. You can do either of the three things :-
1. Add a default value to the column supplier_id Using -
ALTERTABLE `xxx` ALTER `supplier_id` SETDEFAULTNULL
2. Supply some value to the supplier_id column during insertion.
3. Add an auto increment to the column and add a primary key to it using the code :-
ALTERTABLE `xxx` CHANGE `supplier_id` `supplier_id` INT(10)AUTO_INCREMENT PRIMARY KEY;
Solution 2:
To solve this, either supply a value for supplier_id when you do the INSERT, or make the column nullable in the DB.
Solution 3:
There might be two cases.
You have declared the column's default value as NONE and are not not passing any value to it while inserting.
You have declared the column in database, but you have not declared the same in your entity object, which is causing the error.
Solution 4:
I added this property
<propertyname="hbm2ddl.auto">create</property>into hibernate.cfg.xml file, and it worked for me.
Solution 5:
You are using table where you have supplier_id column . it does not have default value ,at insertion time this column not getting any value . initialize supplier_id column with some default value , or use auto increment if you are using supplier_id as a primary key.
Post a Comment for "Java.sql.sqlexception: Field 'supplier_id' Doesn't Have A Default Value"