In this tutorial we will learn How to solve : org.hibernate.HibernateException: The database returned no natively generated identity value.
Also read : FileNotFoundException in java
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;
`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
`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
FileNotFoundException in java
SQLException in java
What is java.lang.InterruptedException in java
when java.lang.ClassNotFoundException occurs in java
Most common and frequently occurring unchecked (runtime) in java.
What is java.lang.NullPointerException in java, when it occurs,how to handle, avoid and fix it
NumberFormatException in java
IndexOutOfBoundsException in java
When java.lang.ArrayIndexOutOfBoundsException occurs in java
When java.lang.StringIndexOutOfBoundsException occurs in java
java.lang.ArithmeticException in java - Divide number by zero
When dividing by zero does not throw ArithmeticException in java