0

我有一个用 8 列与 DB 映射的类,但在 hql 中,我在 select 语句中创建第 9 列,并带有 case when 语句。它给出了意外的toekn,似乎是语法错误。但我无法弄清楚确切的语法错误。

我得到的例外

org.jboss.resteasy.spi.UnhandledException:javax.ejb.EJBException:java.lang.IllegalArgumentException:org.hibernate.hql.ast.QuerySyntaxException:意外令牌:(靠近第 1 行,第 353 列

[选择 un.id, un.timestamp, un.recipientUser, un.sendingUser,un.messageType, un.body, un.title, un.readTimestamp, case when sentUser > recipientUser 然后 CONCAT(sendingUser,'-',recipientUser) ELSE CONCAT(recipientUser,'-',sendingUser) END as normalised_message_parties from com.xxxxx.platform.xxx.notification.xxxxxx.UserNotification un inner join ( 选择 max(timestamp) 作为时间戳,sendingUser > recipientUser 然后 CONCAT(sendingUser, '-',recipientUser) ELSE CONCAT(recipientUser,'-',sendingUser) END as normalised_message_parties from com.xxxxx.platform.xxx.notification.xxxxxx.UserNotification un where un.sendingUser like :userID or un.recipientUser like :userID group通过 normalised_message_parties) 作为 m on ( m.normalised_message_parties = normalised_message_parties 和 m.timestamp = un.时间戳)按时间戳 DESC 排序]

找不到问题..我不知道你还需要什么来帮助我..所以请告诉我我会发布它..但据我所知..查询语法中的问题中继。我正在使用休眠 3.4

4

1 回答 1

0

专栏不是问题。您不能在 FROM 子句中使用子选择。Hibernate 文档指出,这仅在 SELECT 或 WHERE 子句中才有可能。你需要

  • 重写您的查询或
  • 提供观点

有关更多详细信息,请参阅Hibernate 文档

于 2012-12-06T09:40:36.490 回答