SSH框架整合遇到的错误——Hibernate查询语句出现错误

在调试前台注册界面,填写注册信息,用户名Ajax异步验证时报错,报错文件在Dao文件的查询语句中。

报错信息:

java.lang.IllegalArgumentException: org.hibernate.QueryException: Legacy-style query parameters (`?`) are no longer supported; use JPA-style ordinal parameters (e.g., `?1`) instead : from com.itcast.shop.user.vo.User where username = ? [from com.itcast.shop.user.vo.User where username = ?]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:133)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:713)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

错误原因:find方法过时,导致HQL语句格式必须改变才能使用。

将HQL语句中的"?"改为JPA-style:

String hql="from User where username = ?0";

这样就可以正确查询到信息了。

猜你喜欢

转载自www.cnblogs.com/aishanyishi/p/9249027.html