我目前正在研究一个需要执行休眠查询的 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 结束时的情况),总和(当 l.details 像'%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()) or (l.username in() or l.username in())) then 1 else 0 end), sum(case when l.details like ' %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 when l. '%Gender: Male.%'之类的详细信息和 l.event = :actDeletionEvent then 1 else 0 end), sum(当 l.deletion 像 '%Gender: Female.%' 和 l.event = :actDeletionEvent then 1 else 0 end), sum(当 l.deletion. event = :actDeletionEvent then 1 else 0 end), sum(当 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 ph.gov.csc.comex.log.AuditLog l其中 l.dateCreated >= :startDate 和 l.dateCreated < :endDate]%Gender: Male.%' and l.event = :actPurgedEvent then 1 else 0 end), sum(当 l.details 像 '%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 and l.dateCreated < :endDate]%Gender: Male.%' and l.event = :actPurgedEvent then 1 else 0 end), sum(当 l.details 像 '%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 and l.dateCreated < :endDate]
我将如何解决这个问题?请帮忙!谢谢!