Questions about placeholders after Hibernate4.1

Source: Internet
Author: User

After Hibernate 4.1, the placeholder for query parameters in HQL has been improved, and if you still use old-fashioned placeholders there will be a warning message similar to the following

[Main] WARN  [org.hibernate.hql.internal.ast.hqlsqlwalker]–[deprecation] encountered positional parameter near line 1, Column.  Positional parameter is considered deprecated; Use named parameters or Jpa-style positional parameters instead.

As can be seen from the warning message, it is recommended to replace the old placeholder Query method with either the named parameter or the JPA placeholder.

For example, the old placeholder query code snippet:

String hql = "Select t from Blog t where t.site=?"  = getsession (). CreateQuery (HQL); Query.setparameter (0, "micmiu.com");

Method One: Change the way to named parameters:

// How to name Parameters String hql2 = "Select t from Blog t where t.site=:site"= getsession (). CreateQuery (HQL2); query2.setparameter ("Site", "micmiu.com");

Method Two: How to change to JPA placeholders:

// JPA Placeholder Mode String hql3 = "Select t from Blog t where t.site=?0"= getsession (). CreateQuery (HQL3); query2.setparameter c7> "0", "micmiu.com");

The following two query methods will not have the alarm information generated.

This article describes the end of @michael Sun.

original articles, reproduced please specify: reproduced from micmiu– software development + life bit [http://www.micmiu.com/]

This article link address: http://www.micmiu.com/j2ee/hibernate/hql-positional-parameter/

Questions about placeholders after Hibernate4.1

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.