Search code examples
javahibernatespring-mvcdb2websphere

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.


Solution

  • 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.