Solved : org.hibernate.HibernateException: The database returned no natively generated identity value


In this tutorial we will learn How to solve : org.hibernate.HibernateException: The database returned no natively generated identity value.



Recently I faced this Exception. It is very easy to solve org.hibernate.HibernateException: The database returned no natively generated identity value.

Follow two steps to solve org.hibernate.HibernateException: The database returned no natively generated identity value>
  • First set primary key in table.
  • And then set it to auto increment.

Scenario where I got org.hibernate.HibernateException: The database returned no natively generated identity value.
My table was like this in MySql >
CREATE TABLE `msw_iap` (
`ID` INT(12) NOT NULL,
`NAME` VARCHAR(12) NULL DEFAULT NULL,
PRIMARY KEY (`ID`),
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT;
I made ID as primary key and then set it auto_increment.
So my table started looking like this in MySql >
CREATE TABLE `msw_iap` (
`ID` INT(12) NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(12) NULL DEFAULT NULL,
PRIMARY KEY (`ID`),
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=1;

Summary -
So In this tutorial we will learned How to solve : org.hibernate.HibernateException: The database returned no natively generated identity value.


Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>

Exceptions Tutorial in java in detail with diagrams and programs



Most common and frequently occurring unchecked (runtime) in java.
eEdit
Must read for you :