访问Grails Groovy域对象中的Map

时间:2015-01-14 19:14:49

标签: arrays grails groovy

我用Grails得到了一些非常奇怪的结果,我创建并将对象保存到db,可以看到通过dbconsole创建的,但是后来无法使用动态查找器检索它。

我的应用程序按顺序从队列中读取消息,接收激活消息,然后接收一系列移动消息。所有消息都带有一个共同的train_id字段。我处理激活,保存它,然后稍后当移动消息从移动消息中提取train_id并使用它来查找持久对象时。

这是代码

// from the activation
def train = new Train ()
...set attribute values here
train.save(flush: true, failOnError: true)

// then for the movement
def handleTmMessage(Map tm) {
Map body = tm["body"]
System.out.println "Movement: ${body}"
System.out.println "body[]:" + body["train_id"] + ":"
System.out.println "body.getAt:" + body.getAt("train_id") + ":"
System.out.println "Looking for train: " + body["train_id"]
String lookupId = body["train_id"]                         // <- something is wrong here
def train = Train.findByTrainUid(lookupId)               // <- This does not work
//def train = Train.findWhere(trainUid: "042H41MW14")      // <- This works !
//def train = Train.findWhere(trainUid: body["train_id"])  // <- This does not work
println train
println train.trainUid
}

这是输出     运动:

[actual_timestamp:1421261040000, auto_expected:true, correction_ind:false, current_train_id:, delay_monitoring_point:false, direction_ind:DOWN, division_code:60, event_source:AUTOMATIC, event_type:DEPARTURE, gbtt_timestamp:1421260980000, line_ind:, loc_stanox:04025, next_report_run_time:4, next_report_stanox:04010, offroute_ind:false, original_loc_stanox:, original_loc_timestamp:, planned_event_type:DEPARTURE, planned_timestamp:1421261010000, platform:, reporting_stanox:00000, route:2, timetable_variation:1, toc_id:60, train_file_address:null, train_id:042H41MW14, train_service_code:13560015, train_terminated:false, variation_status:LATE]
    body[]:042H41MW14:
    body.getAt:042H41MW14:
    Looking for train: 042H41MW14
    null
    java.lang.NullPointerException: Cannot get property 'trainUid' on null object

注意:消息使用train_id,Train对象使用trainUid

所以我认为对地图的查找有点失败?任何想法都非常感激

马丁

0 个答案:

没有答案