当前位置: 代码迷 >> Java Web开发 >> 请大家帮小弟我看一上在Hibernate上报这个错误该怎么办?多谢
  详细解决方案

请大家帮小弟我看一上在Hibernate上报这个错误该怎么办?多谢

热度:631   发布时间:2016-04-16 23:55:51.0
请大家帮我看一下在Hibernate下报这个异常该怎么处理?谢谢!

请大家帮我看一下在Hibernate下报这个异常改怎么处理!

我在网上查了一下,说把你的from后面改成是实体类而不是表名,注意大小写。

可是我在代码里改成…… 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 ...” 
------解决方案--------------------
引用:
楼主主要区分一下hql语句和sql语句的,hql语句这么写:“from 实体类名 where ...” 而sql语句则这么写:“select * from 表名 where ...”

正解!
------解决方案--------------------
引用:
请大家帮我看一下在Hibernate下报这个异常改怎么处理!

我在网上查了一下,说把你的from后面改成是实体类而不是表名,注意大小写。

可是我在代码里改成…… select c from Clazz c there c.name=:name ……运行时还是不行?

Exception in thread "main" org.hibernate.hql.ast.QuerySynt……

“ 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);

  相关解决方案