SSH查询报错

djl6452 2012-03-26 03:04:49
action:

Count coun=adPaiService.getselectCountIp(ip);

dao层:

Object obj = super.getHibernateTemplate().execute(new HibernateCallback()
{
public Object doInHibernate(Session session) throws HibernateException, SQLException
{
Query query=session.createQuery("from Count where IP= :IP");
query.setString("IP", ip);
Count count=(Count) query.uniqueResult();
return count;
}
});
return (Count)obj;

报错:
ERROR 2012-03-26 14:51:23112 org.hibernate.hql.PARSER line 1:6: unexpected token: Count
ERROR 2012-03-26 14:51:23122 cn.zmcn.adboss.contract.action.AdPaiAction cn.zmcn.adboss.contract.action.AdPaiAction@1cdc7e0
org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: Count near line 1, column 6 [from Count where IP= :IP]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: Count near line 1, column 6 [from Count where IP= :IP]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
at cn.zmcn.adboss.contract.dao.hibernate.AdPaiDaoHibernate.getselectCountIp(AdPaiDaoHibernate.java:109)
at cn.zmcn.adboss.contract.service.impl.AdPaiServiceImpl.getselectCountIp(AdPaiServiceImpl.java:206)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy22.getselectCountIp(Unknown Source)
at cn.zmcn.adboss.contract.action.AdPaiAction.load(AdPaiAction.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept

这个怎么解决
...全文
206 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 djl6452 的回复:]

回复3楼 Count是javabean 表名是count
[/Quote]

Count是关键字,。你的表怎么能去这个名字呢!
成一粒 2012-03-26
  • 打赏
  • 举报
回复
你自己把每次报的错误看看究竟是什么错误。自己要尝试去解决啊。
每次的错误绝对是不可能一样的啊
  • 打赏
  • 举报
回复
Count count=(Count) query.uniqueResult();
很明显Count无法标识!你改成int就OK了!
dryZeng 2012-03-26
  • 打赏
  • 举报
回复
ERROR 2012-03-26 14:51:23112 org.hibernate.hql.PARSER line 1:6: unexpected token: Count
还是这个错误?
你不是把Count改了么?PO名也要改啊。
djl6452 2012-03-26
  • 打赏
  • 举报
回复
还是一样的错误
dryZeng 2012-03-26
  • 打赏
  • 举报
回复
把所有Conut都改成其它不是关键字的还是出错?现在出什么错?
成一粒 2012-03-26
  • 打赏
  • 举报
回复
将上面该改的都改了。如果还不对。加我QQ给你说236556254
成一粒 2012-03-26
  • 打赏
  • 举报
回复
对了。Conut在数据库中是关键字。。。。。。
djl6452 2012-03-26
  • 打赏
  • 举报
回复
加上空的构造函数也行 错误都一样的
成一粒 2012-03-26
  • 打赏
  • 举报
回复
在实体类中加上空的构造函数!!!
djl6452 2012-03-26
  • 打赏
  • 举报
回复
不设参数 直接执行也不行 也报一样的错误
菖蒲老先生 2012-03-26
  • 打赏
  • 举报
回复
那就索性写成

Query query=session.createQuery("from Count where IP= 'XXXXXX'");

不设参数,直接执行试试。。。。。。

[Quote=引用 7 楼 djl6452 的回复:]

查看的是String类型 改成Query query=session.createQuery("from Count where IP= '" + ip + "'");

也是报一样的错
[/Quote]
djl6452 2012-03-26
  • 打赏
  • 举报
回复
public class Count {
private Long id;
private String ip;
private String smartresult;
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getIp()
{
return ip;
}
public void setIp(String ip)
{
this.ip = ip;
}
public String getSmartresult()
{
return smartresult;
}
public void setSmartresult(String smartresult)
{
this.smartresult = smartresult;
}

}

配置文件:
<hibernate-mapping>
<class name="cn.zmcn.adboss.contract.model.Count" dynamic-update="true"
table="count" schema="adboss">
<cache usage="nonstrict-read-write" />
<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="ip" type="java.lang.String">
<column name="IP" />
</property>

<property name="smartresult" type="java.lang.String">
<column name="SMARTRESULT" />
</property>

</class>
</hibernate-mapping>
今儿起叫民工 2012-03-26
  • 打赏
  • 举报
回复
Count 是不是装上关键字了?
djl6452 2012-03-26
  • 打赏
  • 举报
回复
回复3楼 Count是javabean 表名是count
成一粒 2012-03-26
  • 打赏
  • 举报
回复
那么在清空MyECLipse从新运行程序
djl6452 2012-03-26
  • 打赏
  • 举报
回复
查看的是String类型 改成Query query=session.createQuery("from Count where IP= '" + ip + "'");

也是报一样的错
五哥 2012-03-26
  • 打赏
  • 举报
回复
org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: Count near line 1, column 6 [from Count where IP= :IP]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: Count near line 1, column 6 [from Count where IP= :IP]

cn.zmcn.adboss.contract.dao.hibernate.AdPaiDaoHibernate.getselectCountIp(AdPaiDaoHibernate.java:109)

AdPaiDaoHibernate.java:109 查看是什么


dao层:

Object obj = super.getHibernateTemplate().execute(new HibernateCallback()
{
public Object doInHibernate(Session session) throws HibernateException, SQLException
{

Query query=session.createQuery("from Count where IP= '" + ip + "'");
//query.setString("IP", ip);
Count count=(Count) query.uniqueResult();
return count;

}
});
return (Count)obj;

djl6452 2012-03-26
  • 打赏
  • 举报
回复
改成这样也是报一样的错误
成一粒 2012-03-26
  • 打赏
  • 举报
回复
Query query=session.createQuery("from Count where IP= :IP");
应该改成from Count where IP= IP吧
加载更多回复(3)

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧