Announcement Announcement Module
Collapse
No announcement yet.
Problem with getHibernateTemplate().find Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with getHibernateTemplate().find

    In my very first Spring application, i'm getting the following exception when i try to execute the following code. Could some one let me know what's that i'm missing?

    Thanks in advance!



    Code:
    in expected: p [from PROJECT p where p.name = ?]; nested exception is net.sf.hibernate.QueryException: in expected: p [from PROJECT p where p.name = ?]
    
    org.springframework.orm.hibernate.HibernateQueryException: in expected: p [from PROJECT p where p.name = ?]; nested exception is net.sf.hibernate.QueryException: in expected: p [from PROJECT p where p.name = ?]net.sf.hibernate.QueryException: in expected: p [from PROJECT p where p.name = ?]	at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)	at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)	at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)	at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)	at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)	at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)	at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)	at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)	at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)	at org.springframework.orm.hibernate.HibernateTemplate$24.doInHibernate(HibernateTemplate.java:506)	at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:228)	at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:248)	at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:497)	at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:492)	at com.apple.irmt.dao.hibernate.HibernateProjectDao.findProjects(HibernateProjectDao.java:40)	at com.apple.irmt.domain.logic.iRMTImpl.findProjects(iRMTImpl.java:101)	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:295)	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:154)	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:121)	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:143)	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)	at $Proxy0.findProjects(Unknown Source)	at com.apple.irmt.domain.ProjectTests.testInsertProject(ProjectTests.java:65)	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    Code:
    	return getHibernateTemplate().find("from PROJECT p where p.name = ?", projectname);
    Also, getHibernateTemplate().find returns a List. If i want to get just one result(object) using this, do i need to iterate through all the returned results or there is any alternate way to get just what i want?

    Thanks!

  • #2
    Code:
    return getHibernateTemplate().find("from PROJECT p where p.name = ?", projectname);
    Hibernate HQL is case sensitive. How do you spell your class: PROJECT / Project?
    Also, getHibernateTemplate().find returns a List. If i want to get just one result(object) using this, do i need to iterate through all the returned results or there is any alternate way to get just what i want?
    use:
    Code:
      List projects = getHibernateTemplate().find("from Project p where p.name = ?", projectname);
      return (Project) projects .get(0);
    HTH

    Comment


    • #3
      Thanks irbouho. I'll try that. So, 'Project' is the name of the POJO or table??? In my case the class name is 'Project' and the table name is "PROJECT".

      Comment


      • #4
        so you should use:
        Code:
        from Project p where p.name = ?

        Comment


        • #5
          Thanks irbouho.

          Comment

          Working...
          X