Announcement Announcement Module
Collapse
No announcement yet.
JpaTemplate Exception using Hibernate EntityManager Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JpaTemplate Exception using Hibernate EntityManager

    Hi,
    I am getting the following Exception when I try to perform a query from entiry manager:

    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.yadayada.domain.Filter#1]

    The code is:

    Code:
    public Filter findById(int filterId)
    {
         return getJpaTemplate().find(Filter.class, filterId);
    }
    I can't see what the problem is! PK of Filter type is int and the record is in the table.

    It returns the correct result if I use:

    Code:
    List l = getJpaTemplate().find(
                    "SELECT f " +
                    "FROM " + Filter.class.getSimpleName() + " f " +
                    "WHERE f.id = ?1", filterId);
    Any help appreciated! I must be missing something simple here!?!

  • #2
    Is it possible to see the rest of the exception? Is there any more detail in the logs? Have you turned up the logging to see what's going on?

    Comment


    • #3
      Here is the full trace:
      SEVERE: ORA-00903: invalid table name

      12-Mar-2007 12:09:16 org.hibernate.event.def.DefaultLoadEventListener onLoad
      INFO: Error performing load command
      org.hibernate.exception.SQLGrammarException: could not load an entity: [com.yadayada.domain.Filter#33]
      at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:67)
      at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
      at org.hibernate.loader.Loader.loadEntity(Loader.java :1798)
      at org.hibernate.loader.entity.AbstractEntityLoader.l oad(AbstractEntityLoader.java:48)
      at org.hibernate.loader.entity.AbstractEntityLoader.l oad(AbstractEntityLoader.java:42)
      at org.hibernate.persister.entity.AbstractEntityPersi ster.load(AbstractEntityPersister.java:2977)
      at org.hibernate.event.def.DefaultLoadEventListener.l oadFromDatasource(DefaultLoadEventListener.java:39 3)
      at org.hibernate.event.def.DefaultLoadEventListener.d oLoad(DefaultLoadEventListener.java:374)
      at org.hibernate.event.def.DefaultLoadEventListener.l oad(DefaultLoadEventListener.java:137)
      at org.hibernate.event.def.DefaultLoadEventListener.p roxyOrLoad(DefaultLoadEventListener.java:193)
      at org.hibernate.event.def.DefaultLoadEventListener.o nLoad(DefaultLoadEventListener.java:101)
      at org.hibernate.impl.SessionImpl.fireLoad(SessionImp l.java:878)
      at org.hibernate.impl.SessionImpl.get(SessionImpl.jav a:815)
      at org.hibernate.impl.SessionImpl.get(SessionImpl.jav a:808)
      at org.hibernate.ejb.AbstractEntityManagerImpl.find(A bstractEntityManagerImpl.java:174)
      at org.springframework.orm.jpa.JpaTemplate$1.doInJpa( JpaTemplate.java:229)
      at org.springframework.orm.jpa.JpaTemplate.execute(Jp aTemplate.java:191)
      at org.springframework.orm.jpa.JpaTemplate.find(JpaTe mplate.java:227)
      at com.yadayada.dao.impl.JpaFilterDao.findById(JpaFil terDao.java:24)
      at com.yadayada.dao.impl.JpaFilterDaoTest.testFindByI d(JpaFilterDaoTest.java:27)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at junit.framework.TestCase.runTest(TestCase.java:164 )
      at junit.framework.TestCase.runBare(TestCase.java:130 )
      at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
      at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.access$001(AbstractAnn otationAwareTransactionalTests.java:44)
      at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests$1.run(AbstractAnnotati onAwareTransactionalTests.java:112)
      at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTest(AbstractAnnota tionAwareTransactionalTests.java:177)
      at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTestTimed(AbstractA nnotationAwareTransactionalTests.java:150)
      at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runBare(AbstractAnnota tionAwareTransactionalTests.java:108)
      at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:159)
      at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:239)
      at junit.framework.TestResult$1.protect(TestResult.ja va:110)
      at junit.framework.TestResult.runProtected(TestResult .java:128)
      at junit.framework.TestResult.run(TestResult.java:113 )
      at junit.framework.TestCase.run(TestCase.java:120)
      at junit.framework.TestSuite.runTest(TestSuite.java:2 28)
      at junit.framework.TestSuite.run(TestSuite.java:223)
      at org.junit.internal.runners.OldTestClassRunner.run( OldTestClassRunner.java:35)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:38)
      at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
      Caused by: java.sql.SQLException: ORA-00903: invalid table name

      at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:125)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoe r.java:305)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoe r.java:272)
      at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java: 626)
      at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4 CPreparedStatement.java:182)
      at oracle.jdbc.driver.T4CPreparedStatement.execute_fo r_describe(T4CPreparedStatement.java:500)
      at oracle.jdbc.driver.OracleStatement.execute_maybe_d escribe(OracleStatement.java:942)
      at oracle.jdbc.driver.T4CPreparedStatement.execute_ma ybe_describe(T4CPreparedStatement.java:532)
      at oracle.jdbc.driver.OracleStatement.doExecuteWithTi meout(OracleStatement.java:1037)
      at oracle.jdbc.driver.OraclePreparedStatement.execute Internal(OraclePreparedStatement.java:2905)
      at oracle.jdbc.driver.OraclePreparedStatement.execute Query(OraclePreparedStatement.java:2946)
      at org.apache.commons.dbcp.DelegatingPreparedStatemen t.executeQuery(DelegatingPreparedStatement.java:92 )
      at org.hibernate.jdbc.AbstractBatcher.getResultSet(Ab stractBatcher.java:186)
      at org.hibernate.loader.Loader.getResultSet(Loader.ja va:1668)
      at org.hibernate.loader.Loader.doQuery(Loader.java:66 2)
      at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:224)
      at org.hibernate.loader.Loader.loadEntity(Loader.java :1784)
      ... 44 more

      It mentions Invalid table name?!? ...But the explicit query works fine!

      Comment


      • #4
        Ah I figure out what the problem was for myself!

        Cause: As I was running the test class inside eclipse I had not included an orm.xml on the CP. Therefore the default behaviour was to bind the annotated classes to tables of the same name, which don't exist!

        regards

        Comment


        • #5
          Glad you managed to sort this out yourself and thanks for posting back!

          Comment

          Working...
          X