可是我在代码里改成…… select c from Clazz c there c.name=:name ……运行时还是不行?
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: there near line 1, column 51 [select c from com.xsx.hibernate.bean.Clazz c there c.name=:name]
在问一下,这个查询语句中的“:name”是什么意思?起什么作用?
select c from com.xsx.hibernate.bean.Clazz c there c.name = :name
谢谢了!
hibernate
------解决方案-------------------- Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: there near line 1, column 51 [select c from com.xsx.hibernate.bean.Clazz c there c.name=:name]
我看错了 ,还是你写错了 there 还是where?
:name表示name变量值会赋值给c.name
------解决方案-------------------- there 写错了 ------解决方案-------------------- 楼主主要区分一下hql语句和sql语句的,hql语句这么写:“from 实体类名 where ...” 而sql语句则这么写:“select * from 表名 where ...” ------解决方案--------------------
正解! ------解决方案--------------------
“ select c from Clazz c there c.name=:name ”
不是there,应该是where吧
“:name”功能类似于占位符
比如:
Query query = session.createQuery("from Clazz c where c.name=:name");
//参数一:HQL中的参数名"name";参数二:name设置的参数对象
query.setEntity("name", name);