org.hibernate.HibernateException: The database returned no natively generated identity value

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • under mysql, union-subclass doesn't work when calling session.create(); the key cannot be generated since the PLAYER table isn't autoincrement configured (which seems logic). It may be a mistake i did or a mysql limitation, but i wanted to share this unit test with you guys. mapping file: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.eyrolles.sportTracker.model"> <class name="Person" table="PERSON"> <id name="id" column="PERSON_ID"> <generator class="native"/> </id> <property name="name" column="PERSON_NAME"/> <property name="birthday" column="BIRTHDAY"/> <property name="height" column="HEIGHT"/> <property name="weight" column="WEIGHT"/> <union-subclass name="Player" > <property name="specificPlayerProperty" /> </union-subclass> <union-subclass name="Coach" > <property name="specificCoachProperty" /> </union-subclass> </class> </hibernate-mapping> classes public class Person { private Long id; private String name; private Date birthday; private float height; private float weight; ... } public class Player extends Person implements Serializable{ private String specificPlayerProperty; ... } public class Coach extends Person implements Serializable{ private String specificCoachProperty; ... } unitTest (schemaexport activated): public class TestH3Inheritance extends TestCase { public void testMakePersistant() throws Exception { System.out.println("==========testMakePersistant========"); Session session = HibernateUtil.getSession(); Transaction tx=null; try { tx = session.beginTransaction(); Player player = new Player("Anthony"); session.create(player); tx.commit(); } catch (Exception e) { if (tx!=null) tx.rollback(); e.printStackTrace(); throw e; } finally { session.close(); System.out.println("==========testMakePersistant========"); } } ... } stacktrace: create table PERSON ( PERSON_ID bigint not null auto_increment, PERSON_NAME varchar(255), BIRTHDAY datetime, HEIGHT float, WEIGHT float, primary key (PERSON_ID) ) 22:19:01,904 DEBUG SchemaExport:154 - create table Coach ( PERSON_ID bigint not null, PERSON_NAME varchar(255), BIRTHDAY datetime, HEIGHT float, WEIGHT float, specificCoachProperty varchar(255) ) 22:19:01,936 DEBUG SchemaExport:154 - create table Player ( PERSON_ID bigint not null, PERSON_NAME varchar(255), BIRTHDAY datetime, HEIGHT float, WEIGHT float, specificPlayerProperty varchar(255) ) 22:19:01,951 INFO SchemaExport:166 - schema export complete 22:19:01,967 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost/SportTracker Running test... ==========testMakePersistant======== Hibernate: insert into Player (PERSON_NAME, BIRTHDAY, HEIGHT, WEIGHT, specificPlayerProperty) values (?, ?, ?, ?, ?) org.hibernate.HibernateException: The database returned no natively generated identity value at org.hibernate.persister.BasicEntityPersister.getGeneratedIdentity(BasicEntityPersister.java:2020) at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1558) at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1955) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:30) at org.hibernate.event.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:221) at org.hibernate.event.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:148) at org.hibernate.event.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:94) at org.hibernate.event.DefaultCreateEventListener.entityIsTransient(DefaultCreateEventListener.java:105) at org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:65) at org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:33) at org.hibernate.impl.SessionImpl.create(SessionImpl.java:678) at org.hibernate.impl.SessionImpl.create(SessionImpl.java:682) at com.eyrolles.sportTracker.test.TestH3Inheritance.testMakePersistant(TestH3Inheritance.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at com.eyrolles.sportTracker.test.TestCase.runTest(TestCase.java:18) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) i can upload the sources
    via by Anthony Patricio,
  • under mysql, union-subclass doesn't work when calling session.create(); the key cannot be generated since the PLAYER table isn't autoincrement configured (which seems logic). It may be a mistake i did or a mysql limitation, but i wanted to share this unit test with you guys. mapping file: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.eyrolles.sportTracker.model"> <class name="Person" table="PERSON"> <id name="id" column="PERSON_ID"> <generator class="native"/> </id> <property name="name" column="PERSON_NAME"/> <property name="birthday" column="BIRTHDAY"/> <property name="height" column="HEIGHT"/> <property name="weight" column="WEIGHT"/> <union-subclass name="Player" > <property name="specificPlayerProperty" /> </union-subclass> <union-subclass name="Coach" > <property name="specificCoachProperty" /> </union-subclass> </class> </hibernate-mapping> classes public class Person { private Long id; private String name; private Date birthday; private float height; private float weight; ... } public class Player extends Person implements Serializable{ private String specificPlayerProperty; ... } public class Coach extends Person implements Serializable{ private String specificCoachProperty; ... } unitTest (schemaexport activated): public class TestH3Inheritance extends TestCase { public void testMakePersistant() throws Exception { System.out.println("==========testMakePersistant========"); Session session = HibernateUtil.getSession(); Transaction tx=null; try { tx = session.beginTransaction(); Player player = new Player("Anthony"); session.create(player); tx.commit(); } catch (Exception e) { if (tx!=null) tx.rollback(); e.printStackTrace(); throw e; } finally { session.close(); System.out.println("==========testMakePersistant========"); } } ... } stacktrace: create table PERSON ( PERSON_ID bigint not null auto_increment, PERSON_NAME varchar(255), BIRTHDAY datetime, HEIGHT float, WEIGHT float, primary key (PERSON_ID) ) 22:19:01,904 DEBUG SchemaExport:154 - create table Coach ( PERSON_ID bigint not null, PERSON_NAME varchar(255), BIRTHDAY datetime, HEIGHT float, WEIGHT float, specificCoachProperty varchar(255) ) 22:19:01,936 DEBUG SchemaExport:154 - create table Player ( PERSON_ID bigint not null, PERSON_NAME varchar(255), BIRTHDAY datetime, HEIGHT float, WEIGHT float, specificPlayerProperty varchar(255) ) 22:19:01,951 INFO SchemaExport:166 - schema export complete 22:19:01,967 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost/SportTracker Running test... ==========testMakePersistant======== Hibernate: insert into Player (PERSON_NAME, BIRTHDAY, HEIGHT, WEIGHT, specificPlayerProperty) values (?, ?, ?, ?, ?) org.hibernate.HibernateException: The database returned no natively generated identity value at org.hibernate.persister.BasicEntityPersister.getGeneratedIdentity(BasicEntityPersister.java:2020) at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1558) at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1955) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:30) at org.hibernate.event.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:221) at org.hibernate.event.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:148) at org.hibernate.event.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:94) at org.hibernate.event.DefaultCreateEventListener.entityIsTransient(DefaultCreateEventListener.java:105) at org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:65) at org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:33) at org.hibernate.impl.SessionImpl.create(SessionImpl.java:678) at org.hibernate.impl.SessionImpl.create(SessionImpl.java:682) at com.eyrolles.sportTracker.test.TestH3Inheritance.testMakePersistant(TestH3Inheritance.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at com.eyrolles.sportTracker.test.TestCase.runTest(TestCase.java:18) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) i can upload the sources
    via by Anthony Patricio,
    • org.hibernate.HibernateException: The database returned no natively generated identity value at org.hibernate.persister.BasicEntityPersister.getGeneratedIdentity(BasicEntityPersister.java:2020) at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1558) at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1955) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:30) at org.hibernate.event.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:221) at org.hibernate.event.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:148) at org.hibernate.event.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:94) at org.hibernate.event.DefaultCreateEventListener.entityIsTransient(DefaultCreateEventListener.java:105) at org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:65) at org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:33) at org.hibernate.impl.SessionImpl.create(SessionImpl.java:678) at org.hibernate.impl.SessionImpl.create(SessionImpl.java:682) at com.eyrolles.sportTracker.test.TestH3Inheritance.testMakePersistant(TestH3Inheritance.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at com.eyrolles.sportTracker.test.TestCase.runTest(TestCase.java:18) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
    No Bugmate found.