【发布时间】:2012-06-26 10:02:09
【问题描述】:
我目前正在处理一个需要执行休眠查询的 grails 项目。每次我使用数据库上的现有数据运行代码时,一切正常。但是,如果我在数据库为空的情况下运行它,则会引发错误。
这是我的代码:
def actActivation = AuditLog.executeQuery("select ll.username from AuditLog ll where ll.event = ? ",[AuditLogEvent.ACCOUNT_ACTIVATION])
def actDeleted = AuditLog.executeQuery("select ll.username from AuditLog ll where ll.event = ? ",[AuditLogEvent.ACCOUNT_DELETION])
def actPurged = AuditLog.executeQuery("select ll.username from AuditLog ll where ll.event = ? ",[AuditLogEvent.ACCOUNT_PURGING])
def list = AuditLog.executeQuery("""select sum(case when l.details like '%Gender: Male.%' and l.event = :actActivationEvent then 1 else 0 end),
sum(case when l.details like '%Gender: Female.%' and l.event = :actActivationEvent then 1 else 0 end),
sum(case when l.event = :actActivationEvent then 1 else 0 end),
sum(case when l.details like '%Gender: Male.%' and l.event = :actFinishRegEvent and ((l.username not in(:actActivation)) or (l.username in(:actDeleted) or l.username in(:actPurged))) then 1 else 0 end),
sum(case when l.details like '%Gender: Female.%' and l.event = :actFinishRegEvent and ((l.username not in(:actActivation)) or (l.username in(:actDeleted) or l.username in(:actPurged))) then 1 else 0 end),
sum(case when l.event = :actFinishRegEvent and ((l.username not in(:actActivation)) or (l.username in(:actDeleted) or l.username in(:actPurged))) then 1 else 0 end),
sum(case when l.details like '%Gender: Male.%' and l.event = :actDeletionEvent then 1 else 0 end),
sum(case when l.details like '%Gender: Female.%' and l.event = :actDeletionEvent then 1 else 0 end),
sum(case when l.event = :actDeletionEvent then 1 else 0 end),
sum(case when l.details like '%Gender: Male.%' and l.event = :actPurgedEvent then 1 else 0 end),
sum(case when l.details like '%Gender: Female.%' and l.event = :actPurgedEvent then 1 else 0 end),
sum(case when l.event = :actPurgedEvent then 1 else 0 end)
from AuditLog l
where l.dateCreated >= :startDate and l.dateCreated < :endDate""",
[
actActivationEvent:AuditLogEvent.ACCOUNT_ACTIVATION,
actDeletionEvent:AuditLogEvent.ACCOUNT_DELETION,
actPurgedEvent:AuditLogEvent.ACCOUNT_PURGING,
actFinishRegEvent:AuditLogEvent.FINISH_REGISTRATION,
actActivation:actActivation,
actDeleted:actDeleted,
actPurged:actPurged,
startDate: startDate,
endDate:endDate
])
这是我在数据库为空的情况下执行代码时的错误消息。
类:org.hibernate.hql.ast.QuerySyntaxException
消息:
子树的意外结束[选择总和(当 l.details 像 '%Gender: Male.%' 和 l.event = :actActivationEvent 然后 1 else 0 结束时的情况),sum(当 l.details 像 '%Gender 这样的情况: Female.%' and l.event = :actActivationEvent then 1 else 0 end), sum(l.event = :actActivationEvent then 1 else 0 end), sum(l.details like '%Gender: Male. %' and l.event = :actFinishRegEvent and ((l.username not in()) or (l.username in() or l.username in())) then 1 else 0 end), sum(case when l. '%Gender: Female.%' and l.event = :actFinishRegEvent and ((l.username not in()) or (l.username in() or l.username in())) then 1 else 0 end ), sum(当 l.event = :actFinishRegEvent and ((l.username not in()) or (l.username in() or l.username in())) then 1 else 0 end), sum(case当 l.details 像 '%Gender: Male.%' 和 l.event = :actDeletionEvent 然后 1 else 0 end), sum(当 l.details 像 '%Gender: Female.%' 和 l.event = :actDeletionEvent 时的情况然后 1 else 0 end), sum(当 l.event = :a 时的情况ctDeletionEvent then 1 else 0 end), sum(l.details like '%Gender: Male.%' and l.event = :actPurgedEvent then 1 else 0 end), sum(l.details like '%Gender: Female.%' and l.event = :actPurgedEvent then 1 else 0 end), sum(case when l.event = :actPurgedEvent then 1 else 0 end) from ph.gov.csc.comex.log.AuditLog l where l. dateCreated >= :startDate 和 l.dateCreated
我将如何解决这个问题?请帮忙!谢谢!
【问题讨论】: