The database returned no natively generated identity value

12,306

Solution 1

The fact that this works on one WebSphere server and fails on another although they both connect to the same database suggests that there is an issue with the version of the JDBC driver. I would check that first.

Solution 2

The above Exception can also occur if the @id annotated property mapped column dose not support auto generation of id.

i.e.

@GeneratedValue(strategy = GenerationType.AUTO)

using

Use @GeneratedValue(strategy = GenerationType.IDENTITY)

might solve the problem.

Share:
12,306
Muhammad Imran Tariq
Author by

Muhammad Imran Tariq

I am a passionate Senior Software Engineer. Majorly work in Java and BigData. I completed my masters degree in computer science and since then I developed various business application on different domains including financial systems, digitalsignage, security etc. I am also a good web developer and worked on different websites such as blogs, shopping carts. I have good understanding of programming languages and software development pros and cons.

Updated on June 04, 2022

Comments

  • Muhammad Imran Tariq
    Muhammad Imran Tariq almost 2 years

    I am using IBM DB2 V 9.1.0.356. I am using DB2 JDBC driver version 9.7.

    I am using these technologies for my application.

    Spring MVC, Hibernate, DB2, Websphere

    In my Create Table script; ID column is generated as:

    ID BIGINT GENERATED BY DEFAULT AS IDENTITY
    

    In Java Entity class its configured as:

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column( name = "id", nullable = false  )
    

    When I saves and object by calling this through hibernate:

    *.save(persistentObject);
    

    Data is saved. But I got following Exception:

    org.hibernate.HibernateException: The database returned no natively generated identity value
    at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:90)
    

    Note: My application is configured on two servers on different machines. From one machine I can succefully save data; but from other I got above mentioned exception.