两张表、一张用户表(Tbsysuserinfo)、一张问题表(Tbquestion)
问题表中有用户编号外键hbm映射如下:<many-to-one name="username" class="com.boxun.crm.dao.entities.Tbsysuserinfo" fetch="select" lazy="false">
<column name="USERNAME" precision="22" scale="0">
<comment>客户经理:为当前登录的用户</comment>
</column>
</many-to-one> javaBean:private Tbsysuserinfo username = new Tbsysuserinfo();
public Tbsysuserinfo getUsername() {
return username;
} public void setUsername(Tbsysuserinfo username) {
this.username = username;
}在未配置该映射之前、程序运行正常。
开始我以为数据没有添加关系、这样映射会有问题、但是我映射另一个对象时证明是没有问题的!
不过在添加这个映射后、查询Hql就出错了!public List<Tbquestion> queryTbquestion(String wheres,String whereName,PageInfo pageInfo,Object areaId,String department) throws Exception{
String hql = " from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%' order by t.newtime desc " ;
String hqlCount = " select count(*) " + hql;
//设值给totalCount
pageInfo.setTotalCount(daoHql.listCount(hqlCount));
//设值totalPage
pageInfo.setTotalPage((pageInfo.getTotalCount()+ 10 - 1) / 10);
hql = " select * "+hql+ " order by t.newtime desc " ; //按时间倒序排列
return daoHql.find(hql, 10, pageInfo.getCurPage());
}在daoHql.listCount(hqlCount);的时候没有错误、
错误出现在daoHql.find()这里!
错误信息如下:09:13:00,062 INFO [STDOUT] ERROR [http-0.0.0.0-8080-4] MAIL - 192.168.0.1bin>>queryTbquestionqueryTbquestionunexpected token: * near line 1, column 9 [ select * from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%' order by t.newtime desc ]
09:13:00,062 ERROR [STDERR] org.hibernate.hql.ast.QuerySyntaxException: unexpected token: * near line 1, column 9 [ select * from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%' order by t.newtime desc ]
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
09:13:00,062 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
09:13:00,062 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
09:13:00,062 ERROR [STDERR] at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
09:13:00,062 ERROR [STDERR] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
09:13:00,062 ERROR [STDERR] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
09:13:00,062 ERROR [STDERR] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1586)
09:13:00,062 ERROR [STDERR] at com.boxun.crm.dao.impl.Dao_HqlImp.find(Dao_HqlImp.java:148)
09:13:00,062 ERROR [STDERR] at com.boxun.crm.service.proptype.impl.QuestionImpl.queryTbquestion(QuestionImpl.java:181)我把hql拷贝到PLSQL里面去执行的时候、有可以查询出值来!!!
这是个什么情况???
问题表中有用户编号外键hbm映射如下:<many-to-one name="username" class="com.boxun.crm.dao.entities.Tbsysuserinfo" fetch="select" lazy="false">
<column name="USERNAME" precision="22" scale="0">
<comment>客户经理:为当前登录的用户</comment>
</column>
</many-to-one> javaBean:private Tbsysuserinfo username = new Tbsysuserinfo();
public Tbsysuserinfo getUsername() {
return username;
} public void setUsername(Tbsysuserinfo username) {
this.username = username;
}在未配置该映射之前、程序运行正常。
开始我以为数据没有添加关系、这样映射会有问题、但是我映射另一个对象时证明是没有问题的!
不过在添加这个映射后、查询Hql就出错了!public List<Tbquestion> queryTbquestion(String wheres,String whereName,PageInfo pageInfo,Object areaId,String department) throws Exception{
String hql = " from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%' order by t.newtime desc " ;
String hqlCount = " select count(*) " + hql;
//设值给totalCount
pageInfo.setTotalCount(daoHql.listCount(hqlCount));
//设值totalPage
pageInfo.setTotalPage((pageInfo.getTotalCount()+ 10 - 1) / 10);
hql = " select * "+hql+ " order by t.newtime desc " ; //按时间倒序排列
return daoHql.find(hql, 10, pageInfo.getCurPage());
}在daoHql.listCount(hqlCount);的时候没有错误、
错误出现在daoHql.find()这里!
错误信息如下:09:13:00,062 INFO [STDOUT] ERROR [http-0.0.0.0-8080-4] MAIL - 192.168.0.1bin>>queryTbquestionqueryTbquestionunexpected token: * near line 1, column 9 [ select * from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%' order by t.newtime desc ]
09:13:00,062 ERROR [STDERR] org.hibernate.hql.ast.QuerySyntaxException: unexpected token: * near line 1, column 9 [ select * from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%' order by t.newtime desc ]
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
09:13:00,062 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
09:13:00,062 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
09:13:00,062 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
09:13:00,062 ERROR [STDERR] at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
09:13:00,062 ERROR [STDERR] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
09:13:00,062 ERROR [STDERR] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
09:13:00,062 ERROR [STDERR] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1586)
09:13:00,062 ERROR [STDERR] at com.boxun.crm.dao.impl.Dao_HqlImp.find(Dao_HqlImp.java:148)
09:13:00,062 ERROR [STDERR] at com.boxun.crm.service.proptype.impl.QuestionImpl.queryTbquestion(QuestionImpl.java:181)我把hql拷贝到PLSQL里面去执行的时候、有可以查询出值来!!!
这是个什么情况???
解决方案 »
- 求助各位大侠
- 请问使用HibernateTemplate可以得到insert或update的记录数吗?
- 异常问题
- jsf+spring+hibernate的Error creating bean with name 'sessionFactory' defined in ServletContext resource问题
- 急求 ftp文件下栽如何实现续传?
- 请问谁知道应该把rowset.jar放在什么地方,才可以在程序中使用import sun.jdbc.rowset.*;
- tomcat5.5.4如果不连到公网上,启动后就会报错,而且影响到程序运行。
- 我在applet中用到了org.w3c.dom.*来处理xml,在jbuilder中可以,打成jar在IE中不行。
- jb5.0中是不是没有javax.ejb的包?哪里可以档到?
- 求助大神
- 马士兵老师的视频在哪里下载
- Servlet下得不到参数
String hql = " from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%'这个hql语句其实最原始不是这样写的!后面的时间排序也没有!
是我大意了。
因为我这边有很多条件才到控制台copy了一下!
原句是这样的: from Tbquestion t where 1=1 到后面才有select * 加上时间降序排列的!
select * from com.boxun.crm.dao.entities.Tbquestion t where 1=1 and t.rid like '0851%' order by t.newtime desc所以可以把 select * 去掉
即
hql = hql+ " order by t.newtime desc " ; //按时间倒序排列
09:35:54,765 ERROR [STDERR] org.hibernate.exception.GenericJDBCException: could not execute query
09:35:54,765 ERROR [STDERR] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
09:35:54,765 ERROR [STDERR] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
09:35:54,765 ERROR [STDERR] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
09:35:54,765 ERROR [STDERR] at org.hibernate.loader.Loader.doList(Loader.java:2235)
09:35:54,765 ERROR [STDERR] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
09:35:54,765 ERROR [STDERR] at org.hibernate.loader.Loader.list(Loader.java:2124)
09:35:54,765 ERROR [STDERR] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:411)
09:35:54,765 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
09:35:54,765 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
09:35:54,765 ERROR [STDERR] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1084)
09:35:54,765 ERROR [STDERR] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
09:35:54,765 ERROR [STDERR] at com.boxun.crm.dao.impl.Dao_HqlImp.find(Dao_HqlImp.java:156)
09:35:54,765 ERROR [STDERR] at com.boxun.crm.service.proptype.impl.QuestionImpl.queryTbquestion(QuestionImpl.java:181)
不知道是分页还是什么情况、Hibernate总会给在原来的sql基础上加上 select * from () where rownum <= ?
肯定是hql语句有问题。
select * from () where rownum <= ?
这样的话就会出现跟加上 select T 一样的错误!
还有以前没有加上配置的时候、运行也是没有问题!
就是不知道现在这是个什么情况!
在页面上直接username.getUserName();这样在页面能取到值!
所以映射是没有问题的!
应该就是在Hql这边出了问题了!
throws HibernateException {
if (null == hql || hql.equals("")) {
return null;
}
query = this.getSession().createQuery(hql);
if (row > 0 && pages > 0) {
// 取得每页显示结果集
query.setMaxResults(row);
// 取得当前页码所要显示的结果集
query.setFirstResult(row * (pages - 1));
} return query.list(); }
但是这样我页面用起来有点麻烦!
query.setFirstResult(row * (pages - 1)).setMaxResults(row)然后select * 去掉看看打印的hql是什么样子
hql + " order by t.newtime desc " ;if (row > 0 && pages > 0) {
query.setFirstResult(row * (pages - 1)).setMaxResults(row);
// 取得每页显示结果集
//query.setMaxResults(row);
// 取得当前页码所要显示的结果集
//query.setFirstResult(row * (pages - 1));
}Hibernate: select * from ( select tbquestion0_.QID as QID46_, tbquestion0_.ECID as ECID46_, tbquestion0_.ECNAME as ECNAME46_, tbquestion0_.CLIENTNAME as CLIENTNAME46_, tbquestion0_.PHONE as PHONE46_, tbquestion0_.TITLE as TITLE46_, tbquestion0_.INFOMSG as INFOMSG46_, tbquestion0_.QUESTIONSTA as QUESTION8_46_, tbquestion0_.RESERVETIME as RESERVET9_46_, tbquestion0_.OVERRESTIME as OVERRES10_46_, tbquestion0_.OVERREMARK as OVERREMARK46_, tbquestion0_.FILEURL as FILEURL46_, tbquestion0_.NEWTIME as NEWTIME46_, tbquestion0_.UPTIME as UPTIME46_, tbquestion0_.UPPEOPLE as UPPEOPLE46_, tbquestion0_.USERNAME as USERNAME46_, tbquestion0_.DEPARTMENT as DEPARTMENT46_, tbquestion0_.STATUS as STATUS46_, tbquestion0_.RETURNNAME as RETURNNAME46_, tbquestion0_.RETURNSUBMIT as RETURNS20_46_, tbquestion0_.RETURNINQUIRY as RETURNI21_46_, tbquestion0_.RETURNTIME as RETURNTIME46_, tbquestion0_.RETURNTIME2 as RETURNTIME23_46_, tbquestion0_.APPRAISE as APPRAISE46_, tbquestion0_.IDEA as IDEA46_, tbquestion0_.MAINNAME as MAINNAME46_, tbquestion0_.ATIME as ATIME46_, tbquestion0_.CALLID as CALLID46_, tbquestion0_.RID as RID46_, tbquestion0_.TEMP1 as TEMP30_46_, tbquestion0_.TEMP2 as TEMP31_46_, tbquestion0_.TEMP3 as TEMP32_46_ from GZYD.TBQUESTION tbquestion0_ where 1=1 and (tbquestion0_.RID like '0851%') order by tbquestion0_.NEWTIME desc ) where rownum <= ?还是一样的~~~!!!
10:17:17,468 INFO [STDOUT] ERROR [http-0.0.0.0-8080-3] MAIL - 192.168.0.1bin>>queryTbquestionqueryTbquestioncould not execute query
10:17:17,468 ERROR [STDERR] org.hibernate.exception.GenericJDBCException: could not execute query
where 1=1 and (tbquestion0_.RID like '0851%') 这生成的sql有问题吧,应该无法执行吧
11:01:53,953 INFO [STDOUT] Hibernate: select count(tbquestion0_.CID) as col_0_0_ from GZYD.TBQUESTIONCHANGE tbquestion0_, GZYD.TBQUESTION tbquestion1_ where tbquestion1_.QID=tbquestion0_.QID and (tbquestion1_.RETURNTIME is null) and (tbquestion1_.RETURNTIME2 is null) and (tbquestion0_.RID like '0851%')
11:01:53,953 INFO [STDOUT] Hibernate: select * from ( select tbquestion0_.CID as col_0_0_, tbquestion1_.TITLE as col_1_0_, tbquestion1_.RESERVETIME as col_2_0_, tbquestion0_.CHANGEOPERATE as col_3_0_ from GZYD.TBQUESTIONCHANGE tbquestion0_, GZYD.TBQUESTION tbquestion1_ where tbquestion1_.QID=tbquestion0_.QID and (tbquestion1_.RETURNTIME is null) and (tbquestion1_.RETURNTIME2 is null) and (tbquestion0_.RID like '0851%') order by tbquestion0_.CREATETIME desc ) where rownum <= ?
11:01:53,968 INFO [STDOUT] INFO [http-0.0.0.0-8080-7] OperationTxt - 192.168.0.1bin>>queryTbquestionChange返回[Ljava.lang.Object;@1b04652这是加上Hibernate的分页过后、他生成的Hql语句!
是可以的、上面的这个hql就可以!
事实证明这样是可以的!
所以...........
我很纠结、查询另外一个实体的时候没有问题!
这个实体我只是加上了这么一个配置就完蛋了!
以前运行也是可以的!
我的错、耽误大家宝贵的时间!
抱歉了:
问题是这样的~~~!!!
关联主键的字段是Long类型!Oracle数据中用Number表示!
而外键在数据库则是用Varchar2类型表示!
Ok、结贴!
换成Long或者Integer的!