Results 1 to 3 of 3

Thread: hibernateTemplate.update query error in spring

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    1

    Default hibernateTemplate.update query error in spring

    I want to update the database from an input form. I am using hibernate template in spring to deal with database transactions.

    Following i the code where i am encountering an error.

    Code:
    String firstName=request.getParameter("first_name");
          String place=request.getParameter("place");
       hibernateTemplate.update("update Details set place =?"+place+" WHERE first_name=?"+firstName+"");
    I want to update the place for a particular name. The above hibernate query is giving this error.

    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: java.lang.String; nested exception is org.hibernate.MappingException: Unknown entity: java.lang.String
    I am able to run insert and find queries successfully, so i am sure about the configuration in the XML files.

    Can anyone suggest me right way of writing the above query.

    Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    108

    Default

    Looks like you're generating invalid SQL.

    You've got bind parameters (?) and parameters in the same string.

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    1) NEVER NEVER NEVER use string concat to create a query
    2) You are mixing ? + the actual value
    3) You are using hibernate so create HQL not SQL
    4) Don't use hibernateTemplate as it isn't recommended anymore.
    5) Read the javadocs
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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