JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Object Relational Mapping » Hibernate  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
話題被移動
該話題已被移動 - koji , 2006-11-06 22:07
如果您尚不清楚該話題被移動的原因,請參考論壇規則以及本版公告或者聯系本版版主。
本主題所含的標籤
無標籤
作者 Hibernate 查詢數據時報錯,請問這是什麽原因呢?急死了!
ouhn





發文: 1
積分: 0
於 2006-11-06 16:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
报错如下: 头都大了,还是没弄好,请大家帮忙。。

java.lang.RuntimeException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: Member near line 1, column 14 [select count(Member) from com.ouhn.wms.warehouse.vos.Member Member]
com.ouhn.wms.warehouse.vos.MemberDAO.findSQL(MemberDAO.java:153)
com.ouhn.wms.warehouse.action.QueryAction.execute(QueryAction.java:128)

相关代码如下 :
1.MemberDAO.Java:
public List findSQL(String sql, String countsql, int ipage)
throws HibernateException {
Session session = HibernateSessionFactory.getSession();
try {
// 提取記錄總數
Iterator results = session.createQuery(countsql).iterate();
while (results.hasNext()) {
rowCount = (Integer) results.next();
}

2.QueryAction.Java:
String sql ="from com.ouhn.wms.warehouse.vos.Member Member";
………………………………
Collection col = queryDAO.findSQL("select Member "+sql,"select count(Member) "+sql,ipage);
request.setAttribute("Member", col);

3.Member 为oracle 表 MEMBER 对应生成的类(对象),这里会不会有问题呢?是不是和某些关键字重复了??

4.在這個論壇裏找到一篇類似的,如下地址:
http://www.javaworld.com.tw/jute/post/print?bid=41&id=146955
但是幫助不大,我的錯誤依舊…………

哎,弄了一天了,還是沒有弄出來,還望高手指點啊,先謝謝了……

Question Question Question


reply to postreply to post
作者 Re:Hibernate 查詢數據時報錯,請問這是什麽原因呢?急死了! [Re:ouhn]
koji

秒速5センチメートル

站長

發文: 8415
積分: 19
於 2006-11-06 22:07 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
select member from Member member
大小寫改一下
改這樣看看

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:Hibernate 查詢數據時報錯,請問這是什麽原因呢?急死了! [Re:ouhn]
Cryhard





發文: 8
積分: 0
於 2006-11-28 15:29 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你这种拼HQL查询语句的方法完全还是JDBC SQL的路子,那你用Hibernate有什么意义吗?

reply to postreply to post
作者 Re:Hibernate 查詢數據時報錯,請問這是什麽原因呢?急死了! [Re:ouhn]
jojoyang





發文: 27
積分: 0
於 2006-12-13 08:47 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你这种拼HQL查询语句的方法完全还是JDBC SQL的路子,那你用Hibernate有什么意义吗?

有時候Hiberante實現不了一些比解復雜的報表SQL,隻能用JDBC SQL的這種方法把sql放到mapping file裡羅


reply to postreply to post
作者 Re:Hibernate 查詢數據時報錯,請問這是什麽原因呢?急死了! [Re:ouhn]
arthuroy





發文: 106
積分: 3
於 2006-12-19 22:01 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請換為
select count(m) from com.ouhn.wms.warehouse.vos.Member m

看來是因為 member 這個字是保留字?!

我今天也遇到這個問題,原本是寫:
select member from Member m where member.siteAccount.name = :name
結果也是出現
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: member near line 1, column 8 [select member from com.blah.blah.domain.Member as member where member.siteAccount.name = :name]

後來改為
select m from Member m where m.siteAccount.name = :name

就 OK 了。


reply to postreply to post
Self-Pity

I never saw a wild thing sorry for itself.
A small bird will drop frozen dead from a bough
without ever having felt sorry for itself.
» JWorld@TW »  Object Relational Mapping » Hibernate

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8