我有一個grails應用程序,它具有創建報告的服務。該報告定義爲:Grails服務不保存域對象當被Message Queue觸發時
class Report {
Date createDate
String reportType
List contents
static constraints = {
}
}
服務生成一份報告,並填充contents
爲由createCriteria
返回一個列表。
我的問題是,我的服務聲稱是保存報告,沒有錯誤出現,日誌記錄表明它的全部存在,但是當我去控制器上顯示該報告的顯示時,它說內容爲空。
另一個相關位,我的Service被一個ActiveMQ消息隊列調用。來自我的報告控制器的消息。
控制器:
class ReportController {
def scaffold = Report
def show = {
def rep = Report.get(params.id)
log.info("Report is " + (rep? "not null" : "null")) //says report is not null
log.info("Report content is " + (rep.contents? "not null" : "null")) //always says report.contents is null.
redirect(action: rep.reportType, model: [results: rep.contents, resultsTotal: rep.contents.size()])
}
}
我的服務,創建報表:
class ReportService {
static transactional = false
static expose = ['jms']
static destination = "Report"
void onMessage(msg)
{
this."$msg.reportType"(msg)
}
void totalQuery(msg)
{
def results = Result.createCriteria().list {
//This returns exactly what i need.
}
Report.withTransaction() {
def rep = new Report(createDate: new Date(), reportType: "totalQuery", contents: results)
log.info("Validation results: ${rep.validate()}")
if(!rep.save(flush: true)) {
rep.errors.each {
log.error(it)
}
}
}
}
有沒有辦法,我在這裏失蹤了一些東西明顯?我的想法是,因爲所有的單元測試工作,hibernate上下文沒有通過消息隊列傳遞。但那會產生例外,不是嗎?我一直在這個問題上打了幾天頭,所以在正確的方向上的一個點會很棒。
感謝,
如何找到保存的報告的ID?我沒有看到任何可以通過它的代碼或記錄它。 `list`操作是否顯示新創建的報告? – 2011-02-18 15:27:12
應用程序使用自動生成的列表視圖。點擊身份證號碼「show」 – 2011-02-18 15:34:57