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

Hibernate JIRA | Anthony Patricio | 1 decade ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    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

    Hibernate JIRA | 1 decade ago | Anthony Patricio
    org.hibernate.HibernateException: The database returned no natively generated identity value
  2. 0

    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

    Hibernate JIRA | 1 decade ago | Anthony Patricio
    org.hibernate.HibernateException: The database returned no natively generated identity value

    Root Cause Analysis

    1. org.hibernate.HibernateException

      The database returned no natively generated identity value

      at org.hibernate.persister.BasicEntityPersister.getGeneratedIdentity()
    2. Hibernate
      SessionImpl.create
      1. org.hibernate.persister.BasicEntityPersister.getGeneratedIdentity(BasicEntityPersister.java:2020)
      2. org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1558)
      3. org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1955)
      4. org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:30)
      5. org.hibernate.event.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:221)
      6. org.hibernate.event.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:148)
      7. org.hibernate.event.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:94)
      8. org.hibernate.event.DefaultCreateEventListener.entityIsTransient(DefaultCreateEventListener.java:105)
      9. org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:65)
      10. org.hibernate.event.DefaultCreateEventListener.onCreate(DefaultCreateEventListener.java:33)
      11. org.hibernate.impl.SessionImpl.create(SessionImpl.java:678)
      12. org.hibernate.impl.SessionImpl.create(SessionImpl.java:682)
      12 frames
    3. com.eyrolles.sportTracker
      TestH3Inheritance.testMakePersistant
      1. com.eyrolles.sportTracker.test.TestH3Inheritance.testMakePersistant(TestH3Inheritance.java:26)
      1 frame
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:324)
      4 frames
    5. JUnit
      TestCase.runTest
      1. junit.framework.TestCase.runTest(TestCase.java:154)
      1 frame
    6. com.eyrolles.sportTracker
      TestCase.runTest
      1. com.eyrolles.sportTracker.test.TestCase.runTest(TestCase.java:18)
      1 frame
    7. JUnit
      TestCase.run
      1. junit.framework.TestCase.runBare(TestCase.java:127)
      2. junit.framework.TestResult$1.protect(TestResult.java:106)
      3. junit.framework.TestResult.runProtected(TestResult.java:124)
      4. junit.framework.TestResult.run(TestResult.java:109)
      5. junit.framework.TestCase.run(TestCase.java:118)
      5 frames
    8. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
      3 frames