Muhammad Imran Tariq
Muhammad Imran Tariq

Reputation: 23352

The database returned no natively generated identity value

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.

Upvotes: 2

Views: 13845

Answers (4)

Nithin karthick
Nithin karthick

Reputation: 25

check primary key in database, if it is not auto increment then you will get this error. enter image description here

Upvotes: 0

user5375222
user5375222

Reputation:

Make sure that while creating your table id field should be marked as auto-increment and then use

@GeneratedValue(strategy = GenerationType.IDENTITY)

Upvotes: 0

Praveen Kumar
Praveen Kumar

Reputation: 1539

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.

Upvotes: 1

Andreas Veithen
Andreas Veithen

Reputation: 9154

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.

Upvotes: 2

Related Questions