Grails service not saving Domain Object When triggered by Message Queue -
i have grails application has service creates reports. report defined as:
class report { date createdate string reporttype list contents static constraints = { } }
the service generates report , populates contents
list returned createcriteria
.
my problem service claims saving report, no errors turn up, logging says there, when go call show controller on report, says contents null.
another relevant bit, service called activemq message queue. message originating report controller.
controller:
class reportcontroller { def scaffold = report def show = { def rep = report.get(params.id) log.info("report " + (rep? "not null" : "null")) //says report not null log.info("report content " + (rep.contents? "not null" : "null")) //always says report.contents null. redirect(action: rep.reporttype, model: [results: rep.contents, resultstotal: rep.contents.size()]) } }
my service creates report:
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 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) } } } }
is there obvious i'm missing here? thought since unit tests work, hibernate context not being passed through message queue. generate exceptions wouldn't it? i've been beating head on problem days, point in right direction great.
thanks,
you can't define arbitrary list
that, it's getting ignored , treated transient. you'd same behavior if had def name
field, since in both cases hibernate doesn't know data type, has no idea how map database.
if want refer collection of results, need hasmany
:
class report { date createdate string reporttype static hasmany = [contents: result] }
if need ordered list, add in list
field same name, , instead of creating set
(the default), list
:
class report { date createdate string reporttype list contents static hasmany = [contents: result] }
your unit tests work because you're not accessing database or using hibernate. think it's best integration test domain classes @ least use in-memory database, , mock domain classes when testing controllers, services, etc.
Comments
Post a Comment