Results 1 to 7 of 7

Thread: Problem with getHibernateTemplate().find()

  1. #1

    Default Problem with getHibernateTemplate().find()

    Hi,

    Im working on my first spring Application. I hav encountered a problem with getHibernateTemplate().find().

    My query is

    String sQry = " from Patient p where p.sPatientId=?";
    List resultList = getHibernateTemplate().find(sQry,sPatientFullId);

    or

    String sQry = " from Patient p where p.sPatientFullId=?";
    List resultList = getHibernateTemplate().find(sQry,sPatientFullId, Hibernate.STRING);

    but a exception is throwing..


    org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is org.springframework.orm.hibernate.HibernateQueryEx ception: query must begin with SELECT or FROM: 6 [6]; nested exception is net.sf.hibernate.QueryException: query must begin with SELECT or FROM: 6 [6]
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:408)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:350)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


    root cause

    org.springframework.orm.hibernate.HibernateQueryEx ception: query must begin with SELECT or FROM: 6 [6]; nested exception is net.sf.hibernate.QueryException: query must begin with SELECT or FROM: 6 [6]
    org.springframework.orm.hibernate.SessionFactoryUt ils.convertHibernateAccessException(SessionFactory Utils.java:595)
    org.springframework.orm.hibernate.HibernateAccesso r.convertHibernateAccessException(HibernateAccesso r.java:353)
    org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:369)
    org.springframework.orm.hibernate.HibernateTemplat e.delete(HibernateTemplate.java:954)
    org.springframework.orm.hibernate.HibernateTemplat e.delete(HibernateTemplate.java:939)
    com.iris.emr.patient.data.hibernate.HibernatePatie ntDao.deletePatient(HibernatePatientDao.java:24)
    com.iris.emr.patient.services.impl.PatientServiceI mpl.deletePatient(PatientServiceImpl.java:16)
    com.iris.emr.patient.services.soap.client.ClientCo ntroller.handleRequest(ClientController.java:86)
    org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:45)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:797)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:727)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:396)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:350)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


    root cause

    net.sf.hibernate.QueryException: query must begin with SELECT or FROM: 6 [6]
    net.sf.hibernate.hql.ClauseParser.token(ClausePars er.java:84)
    net.sf.hibernate.hql.PreprocessingParser.end(Prepr ocessingParser.java:142)
    net.sf.hibernate.hql.ParserHelper.parse(ParserHelp er.java:30)
    net.sf.hibernate.hql.QueryTranslator.compile(Query Translator.java:149)
    net.sf.hibernate.hql.QueryTranslator.compile(Query Translator.java:138)
    net.sf.hibernate.impl.SessionFactoryImpl.getQuery( SessionFactoryImpl.java:294)
    net.sf.hibernate.impl.SessionImpl.getQueries(Sessi onImpl.java:1562)
    net.sf.hibernate.impl.SessionImpl.find(SessionImpl .java:1533)
    net.sf.hibernate.impl.SessionImpl.find(SessionImpl .java:1521)
    net.sf.hibernate.impl.SessionImpl.delete(SessionIm pl.java:1668)
    net.sf.hibernate.impl.SessionImpl.delete(SessionIm pl.java:1654)
    org.springframework.orm.hibernate.HibernateTemplat e$27.doInHibernate(HibernateTemplate.java:961)
    org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:364)
    org.springframework.orm.hibernate.HibernateTemplat e.delete(HibernateTemplate.java:954)
    org.springframework.orm.hibernate.HibernateTemplat e.delete(HibernateTemplate.java:939)
    com.iris.emr.patient.data.hibernate.HibernatePatie ntDao.deletePatient(HibernatePatientDao.java:24)
    com.iris.emr.patient.services.impl.PatientServiceI mpl.deletePatient(PatientServiceImpl.java:16)
    com.iris.emr.patient.services.soap.client.ClientCo ntroller.handleRequest(ClientController.java:86)
    org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:45)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:797)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:727)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:396)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:350)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

    Will u help me please?


  2. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    You'd better ask this on the Data Access forum.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3

    Default

    thxs frined

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    I think this is a subtle problem with HB 2 parser - if you specify a property of your bean inside your query (p.sPatientId=?) it will require also a select:
    "SELECT p FROM Patient p where p.sPatientFullId=?"
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5

    Default

    thxs for ur reply. I tried but failed.
    the error is pasted below
    org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is org.springframework.orm.hibernate.HibernateQueryEx ception: query must begin with SELECT or FROM: 6 [6]; nested exception is net.sf.hibernate.QueryException: query must begin with SELECT or FROM: 6 [6]
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:408)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:350)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


    root cause

    org.springframework.orm.hibernate.HibernateQueryEx ception: query must begin with SELECT or FROM: 6 [6]; nested exception is net.sf.hibernate.QueryException: query must begin with SELECT or FROM: 6 [6]
    org.springframework.orm.hibernate.SessionFactoryUt ils.convertHibernateAccessException(SessionFactory Utils.java:595)

  6. #6
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Turn showSQL to true and see what query hibernate tries to generate internally - the query might be altered somewhere along the way.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  7. #7
    Join Date
    Aug 2007
    Posts
    1

    Default check hibernate configuration file

    i think this exception is from configuration of query parser..

    check ur hibernate config..

    don't u config
    query.factory_class = org.hibernate.hql.classic.ClassicQueryTranslatorFa ctory

    ClassicQueryTranslatorFactory can't parsing ur query..


    i romve that config.. it work well..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •