JPQL连接查询的问题

hiker375 2009-10-20 02:15:26
jpql语句如下:
select new ClubTopic(o.id as id,o.title as title,o.member.pcard.picture as cardpicture,o.member.pcard.domain as carddomain,o.visit as visit,b.reply as reply,o.insertTime as insertTime,o.card.name as cardname,o.replyTime as replyTime) from xyw.entity.club.ClubTopic o left join (select count(id) as reply from xyw.entity.club.ClubTopicReply group by topic.id) b on o.id=b.topicid where o.home.id=1 and o.enable=1 order by o.visit DESC

ClubTopic 帖子表 ClubTopicReply 帖子回复表

...全文
195 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
JPQL 的语法错了呗

JPQL 不是 SQL,我记得 LEFT JOIN 里面好像是不能使用子查询的。
hiker375 2009-10-20
  • 打赏
  • 举报
回复
程序报错,
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 278 [select new ClubTopic(o.id as id,o.title as title,o.member.pcard.picture as cardpicture,o.member.pcard.domain as carddomain,o.visit as visit,b.reply as reply,o.insertTime as insertTime,o.card.name as cardname,o.replyTime as replyTime) from xyw.entity.club.ClubTopic o left join (select c.topic.id as topicid,count(c.id) as reply from xyw.entity.club.ClubTopicReply c group by c.topic.id) b with o.id=b.topicid where o.home.id=1 and o.enable=1 order by o.visit DESC]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:624)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
at com.sun.enterprise.util.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:662)
at xyw.service.club.view.bean.ClubBean.getQueryBySql(ClubBean.java:130)
at xyw.service.club.view.bean.ClubBean.listBySql(ClubBean.java:95)
at sun.reflect.GeneratedMethodAccessor174.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
... 99 more
请问哪写错了
  • 打赏
  • 举报
回复
不知道你要问什么!

我帮你把 JPQL 整理一下吧,方便其他朋友来看,我做的只有这些了

 SELECT new ClubTopic(
o.id AS id,
o.title AS title,
o.member.pcard.picture AS cardpicture,
o.member.pcard.domain AS carddomain,
o.visit AS visit,
b.reply AS reply,
o.insertTime AS insertTime,
o.card.name AS cardname,
o.replyTime AS replyTime)
FROM xyw.entity.club.ClubTopic o
LEFT JOIN (SELECT count(id) AS reply
FROM xyw.entity.club.ClubTopicReply
GROUP BY topic.id) b
ON o.id = b.topicidwhere
WHERE o.home.id = 1
AND o.enable = 1
ORDER BY o.visit DESC

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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