30

I'm getting this exception from Hibernate

building session factory
13:32:09,937 INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured
Exception in thread "main" org.hibernate.HibernateException: The database returned no natively generated identity value

What does this mean and how can I solve it? Thanks!

Rup
  • 33,765
  • 9
  • 83
  • 112
Abdul
  • 577
  • 1
  • 5
  • 21

6 Answers6

64

I think it means you're trying to use the IDENTITY ID generator with a table column which is not properly configured. It should be an auto_increment column for the IDENTITY generator to work. Else, the database doesn't return any generated ID.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • 1
    Can anybody add what getting this error might mean on SqlServer (where there is no "auto_increment") property – PandaWood Jan 24 '16 at 23:40
  • 2
    I get this as a one-off error where thousands of rows are created and work but then suddenly this errors turns up once or twice – PandaWood Jul 07 '17 at 02:47
12

We must auto_increment the id column of the table by using below query

ALTER TABLE document MODIFY COLUMN document_id INT auto_increment
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
user4411686
  • 121
  • 1
  • 2
3

And fixing this is as simple as making sure that the Primary Key Column, of the table you are working with, has Auto Increment set.

dade
  • 3,340
  • 4
  • 32
  • 53
3

While creating Table in Database you may have forgot to give Autoincrement to that particular column.

Or

You forgot to annotate in Java class as "Generated Value"

This will work fine

0

Another way to fix this, is to set the Auto_Increment for the ID column of the table

Saurabh Singhal
  • 271
  • 1
  • 5
  • 18
0

In such scenario, you not need to create table manually. It will create by default using hibernate. make change or add in hibernate.cfg.xml >> "hibernate.hbm2ddl.auto" field set to "update".