Announcement Announcement Module
Collapse
No announcement yet.
URGENT: Data Access Problem - please help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • URGENT: Data Access Problem - please help

    Hi,

    Can you please help???

    I'm trying a simple Junit tet to read a db table but I get a java null pointer exception:


    java.lang.NullPointerException.

    at com.test.mainsys.sysmodel.dao.FxRateDAO.findFxRate History(FxRateDAO.java:109)
    at com.test.eq.sysmodel.dao.FxRateDAOTest.testFindFxR ateByHistory(FxRateDAOTest.java:143)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:41)
    at java.lang.reflect.Method.invoke(Method.java:386)
    at junit.framework.TestCase.runTest(TestCase.java:154 )
    at junit.framework.TestCase.runBare(TestCase.java:127 )
    at junit.framework.TestResult$1.protect(TestResult.ja va: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)


    The DAO code is




    public final List findFxRateHistory(
    final String fromCcy,
    final String toCcy
    )
    throws ObjectRetrievalDAOException, FinderDAOException {

    System.out.println(fromCcy);
    System.out.println(toCcy);

    Object[] objectArray = { fromCcy,toCcy };
    Type[] typeArray = { Hibernate.STRING,Hibernate.STRING };

    System.out.println("before list");
    return.getHibernateTemplate().find("from fx_rate where
    ccy1 = ? and ccy=?",
    objectArray,typeArray);

    //NOTE the table name in lowercase.


    }


    In the Junit test:

    dao = (FxRateDAO) getAppCtx().getBean("fx_rate");

    List readFxHistory = dao.findFxRateHistory(fromCc, toCc);

  • #2
    Could you please post the relevant portion of your bean configuration ? and point at where is the line 109 of FxRateDAO.java ?

    Comment


    • #3
      Problem using Alias in hibernate find method

      Hi

      Thanks v. much for that.

      I've spotted why it was returning a null - this was because the domian object name was specified incorrectly. Should be FxRate.

      How that has been fixed another problem. Perhaps an expert could throw some light. The query does not work if I us an alias eg.

      If I use the following its ok, but as soon as i introduce an alias it does not like it :

      This is OK:

      try
      {
      Object[] objectArray = { From, To, Date};
      Type[] typeArray =
      {
      Hibernate.STRING,
      Hibernate.STRING,
      Hibernate.BIG_DECIMAL
      };


      return getHibernateTemplate().find("from FxRate where ccy = ? and ccy1 = ? and date = ?",objectArray,typeArray);
      } catch (DataAccessException e) {
      throw new FinderDAOException("Failed to execute findFXRateHistory", e);
      }


      but on introducing an alias

      try{

      Object[] objectArray = { From, To, Date};
      Type[] typeArray =
      {
      Hibernate.STRING,
      Hibernate.STRING,
      Hibernate.BIG_DECIMAL
      };


      return getHibernateTemplate().find("from FxRate as fx where fx.ccy = ? and fx.ccy1 = ? and fx.date = ?",objectArray,typeArray);
      } catch (DataAccessException e) {
      throw new FinderDAOException("Failed to execute findFXRateHistory", e);
      }


      I get (NB line 112 is the throw clause in catch block above):

      com.test.maintest.fxtest.model.dao.FinderDAOExcept ion: Failed to execute findFXRateHist
      at com.test.maintest.fxtest.model.dao.FXDAO.findFxRat eHistory(FXDAO.java:112)
      at com.test.maintest.fxtest.model.dao.FXDAO$$FastClas sByCGLIB$$c16f65eb.invoke(<generated>)
      at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy. java:149)
      at org.springframework.aop.framework.Cglib2AopProxy$M ethodInvocationImpl.invokeJoinpoint(Cglib2AopProxy .java:878)
      at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :116)
      at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:56)
      at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :138)
      at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:596)
      at com.test.maintest.fxtest.model.dao.FXDAO$$Enhancer ByCGLIB$$a7d1173b.findFxRateHistory(<generated>)
      at com.test.maintest.fxtest.model.dao.FXDAOTest.testF indFxRateByHist(FXDAOTest.java:155)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:79)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:41)
      at java.lang.reflect.Method.invoke(Method.java:386)
      at junit.framework.TestCase.runTest(TestCase.java:154 )
      at junit.framework.TestCase.runBare(TestCase.java:127 )
      at junit.framework.TestResult$1.protect(TestResult.ja va: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:2 08)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:392)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:276)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:167)
      Caused by: org.springframework.orm.hibernate.Hibernatmaintest ueryException: could not resolve property: from_ccy of: com.test.maintest.fxtest.model.domain.FxRate [from com.test.maintest.fxtest.model.domain.FxRate as fx where fx.from_ccy = ? and fx.to_ccy = ? and fx.rate_date = ?]; nested exception is net.sf.hibernate.QueryException: could not resolve property: from_ccy of: com.test.maintest.fxtest.model.domain.FxRate [from com.test.maintest.fxtest.model.domain.FxRate as fx where fx.from_ccy = ? and fx.to_ccy = ? and fx.rate_date = ?]
      at org.springframework.orm.hibernate.SessionFactoryUt ils.convertHibernateAccessException(SessionFactory Utils.java:458)
      at org.springframework.orm.hibernate.HibernateAccesso r.convertHibernateAccessException(HibernateAccesso r.java:234)
      at org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:181)
      at org.springframework.orm.hibernate.HibernateTemplat e.executeFind(HibernateTemplate.java:196)
      at org.springframework.orm.hibernate.HibernateTemplat e.find(HibernateTemplate.java:459)
      at com.test.maintest.fxtest.model.dao.FXDAO.findFxRat eHistory(FXDAO.java:109)
      ... 24 more
      Caused by: net.sf.hibernate.QueryException: could not resolve property: from_ccy of: com.test.maintest.fxtest.model.domain.FxRate [from com.test.maintest.fxtest.model.domain.FxRate as fx where fx.from_ccy = ? and fx.to_ccy = ? and fx.rate_date = ?]
      at net.sf.hibernate.persister.AbstractPropertyMapping .toType(AbstractPropertyMapping.java:38)
      at net.sf.hibernate.hql.PathExpressionParser.getPrope rtyType(PathExpressionParser.java:249)
      at net.sf.hibernate.hql.PathExpressionParser.end(Path ExpressionParser.java:288)
      at net.sf.hibernate.hql.WhereParser.doPathExpression( WhereParser.java:336)
      at net.sf.hibernate.hql.WhereParser.doToken(WherePars er.java:366)
      at net.sf.hibernate.hql.WhereParser.token(WhereParser .java:251)
      at net.sf.hibernate.hql.ClauseParser.token(ClausePars er.java:87)
      at net.sf.hibernate.hql.PreprocessingParser.token(Pre processingParser.java:123)
      at net.sf.hibernate.hql.ParserHelper.parse(ParserHelp er.java:29)
      at net.sf.hibernate.hql.QueryTranslator.compile(Query Translator.java:149)
      at net.sf.hibernate.hql.QueryTranslator.compile(Query Translator.java:138)
      at net.sf.hibernate.impl.SessionFactoryImpl.getQuery( SessionFactoryImpl.java:294)
      at net.sf.hibernate.impl.SessionImpl.getQueries(Sessi onImpl.java:1562)
      at net.sf.hibernate.impl.SessionImpl.find(SessionImpl .java:1533)
      at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.jav a:39)
      at org.springframework.orm.hibernate.HibernateTemplat e$26.doInHibernate(HibernateTemplate.java:465)
      at org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:176)
      ... 27 more

      Comment

      Working...
      X