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