org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [dominio.Piloto#1]

Spring JIRA | Eduardo Rocha | 1 decade ago
  1. 0

    I have a test similar with HibernateTemplateTests, but not using mocks for Hibernate classes, but concrete classes. I have this test: 1 try { 2 Piloto piloto = dao.findById(1); 3 fail("piloto obtido=[" + piloto.toString() + "]"); 4 } catch (ObjectRetrievalFailureException e) { 5 assertEquals(1, e.getIdentifier()); 6 assertEquals(Piloto.class, e.getPersistentClass()); 7 } for the code: public Piloto findById(int id) { return (Piloto) getHibernateTemplate().load(Piloto.class, id); } The database is empty. The test fails AFTER findByid (#2), because the dao seems to use lazy loading, and an exception is throw when a call is made to "piloto.toString()" (#3): org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [dominio.Piloto#1] at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:121) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:78) at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:649) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:85) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:131) at br.com.erocha.formula.dominio.Piloto$$EnhancerByCGLIB$$4514e186.toString(<generated>) at br.com.erocha.formula.infraestrutura.dao.hibernate.HibernatePilotoDaoImplTest.testFindByIdPilotoInexistente(HibernatePilotoDaoImplTest.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:154) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

    Spring JIRA | 1 decade ago | Eduardo Rocha
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [dominio.Piloto#1]
  2. 0

    I have a test similar with HibernateTemplateTests, but not using mocks for Hibernate classes, but concrete classes. I have this test: 1 try { 2 Piloto piloto = dao.findById(1); 3 fail("piloto obtido=[" + piloto.toString() + "]"); 4 } catch (ObjectRetrievalFailureException e) { 5 assertEquals(1, e.getIdentifier()); 6 assertEquals(Piloto.class, e.getPersistentClass()); 7 } for the code: public Piloto findById(int id) { return (Piloto) getHibernateTemplate().load(Piloto.class, id); } The database is empty. The test fails AFTER findByid (#2), because the dao seems to use lazy loading, and an exception is throw when a call is made to "piloto.toString()" (#3): org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [dominio.Piloto#1] at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:121) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:78) at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:649) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:85) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:131) at br.com.erocha.formula.dominio.Piloto$$EnhancerByCGLIB$$4514e186.toString(<generated>) at br.com.erocha.formula.infraestrutura.dao.hibernate.HibernatePilotoDaoImplTest.testFindByIdPilotoInexistente(HibernatePilotoDaoImplTest.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:154) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

    Spring JIRA | 1 decade ago | Eduardo Rocha
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [dominio.Piloto#1]
  3. 0

    Hibernate / Mailing Lists

    sourceforge.net | 1 year ago
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.netvisor.hpsd_middle.persistence.Person#CT7124]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
  6. 0

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.ObjectNotFoundException

      No row with the given identifier exists: [dominio.Piloto#1]

      at org.hibernate.ObjectNotFoundException.throwIfNull()
    2. Hibernate
      ObjectNotFoundException.throwIfNull
      1. org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
      1 frame
    3. Hibernate
      SessionImpl.immediateLoad
      1. org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:121)
      2. org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:78)
      3. org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:649)
      3 frames
    4. Hibernate
      CGLIBLazyInitializer.intercept
      1. org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
      2. org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:85)
      3. org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:131)
      3 frames
    5. br.com.erocha
      HibernatePilotoDaoImplTest.testFindByIdPilotoInexistente
      1. br.com.erocha.formula.dominio.Piloto$$EnhancerByCGLIB$$4514e186.toString(<generated>)
      2. br.com.erocha.formula.infraestrutura.dao.hibernate.HibernatePilotoDaoImplTest.testFindByIdPilotoInexistente(HibernatePilotoDaoImplTest.java:113)
      2 frames
    6. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      4. java.lang.reflect.Method.invoke(Unknown Source)
      4 frames
    7. JUnit
      TestSuite.run
      1. junit.framework.TestCase.runTest(TestCase.java:154)
      2. junit.framework.TestCase.runBare(TestCase.java:127)
      3. junit.framework.TestResult$1.protect(TestResult.java:106)
      4. junit.framework.TestResult.runProtected(TestResult.java:124)
      5. junit.framework.TestResult.run(TestResult.java:109)
      6. junit.framework.TestCase.run(TestCase.java:118)
      7. junit.framework.TestSuite.runTest(TestSuite.java:208)
      8. junit.framework.TestSuite.run(TestSuite.java:203)
      8 frames
    8. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      3 frames