A placeholder in the Hibernate query statement hql? parameter and named parameter: Name set Value method to confuse

Source: Internet
Author: User

Post an exception first

Struts has detected an unhandled exception:Messages:Position beyond number of declared ordinal parameters. Remember that ordinal parameters is 1-based! Position:1file:org/hibernate/engine/query/spi/parametermetadata.java  Stacktracesorg.hibernate.QueryParameterException:Position beyond number of declared ordinal parameters. Remember that ordinal parameters is 1-based! Position:1

Code:

Define HQL
String hql = "from book book where" + "Book.booktype Like:queryargs or" + "book. Booknum Like:queryargs or" + "Book.book Name Like:queryargs or "+" Book.bookauthor Like:queryargs "+" ORDER by Book.booktype, book. Booknum, Book.bookauthor, bo Ok.bookname ";//dao set value in query query = Sessionfactory.getcurrentsession (). CreateQuery (HQL); for (int i = 0; i < Objects.length; i++) {Query.setparameter (I, objects[i]);}

Reason:

The exception is that the placeholder index is out of bounds (overflow) because there is no placeholder "?" in my defined hql, I use a named parameter that should be passed setstring (paraname,paravalue) or Setparameter (Paraname, Paravalue) way to set the value, but I use Setparameter (int arg0, Object arg1) to set the value, so the error!

Workaround:

For me this, I pass: Queryargs all replaced? The way.

A placeholder in the Hibernate query statement hql? parameter and named parameter: Name set Value method to confuse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.