Sunday, June 24, 2012

Strange enhancement exception caused by generic getId() method of morphia model

The exception stack:


morphia model code caused the trouble:


morphia model code that will not cause the trouble:


Root cause: Not found

Wednesday, June 20, 2012

Scope variable not workign in MongoDB MapReduce function

So I am trying to create map reduce aggregation functions. Since I need to aggregate on multiple dimensions, I don't want to copy/paste map and reduce function and only change the dimension from one to another.

I follow the manual http://www.mongodb.org/display/DOCS/MapReduce and defines the scope variable to pass in the dimension info:


// the map function
var map = function() {
    var dimension = this[dimension] ? this[dimension] : "_";
    var key = this.inst + "|" + this.bar + "|" + dimension;
    var result = {hit: 1};
    emit(key, result);
};
// the statement to call mapreduce
db.foo.mapReduce(map, reduce, {
  out: {inline: 1}, 
  query: q, 
  scope: {dimension: "red"}});

I run the above map reduce and found the dimension is always empty unless I noticed that dimension is redefined in the map function. Change the map funciton to the following solves the problem:
// the map function
var map = function() {
    var d= this[dimension] ? this[dimension] : "_"; // changed
    var key = this.inst + "|" + this.bar + "|" + d; // changed
    var result = {hit: 1};
    emit(key, result);
};

Thursday, June 14, 2012

Strange Morphia Exception caused by Rythm


This very strange exception drives me crazy!

The exception pops up when I've updated a model class, and it won't go away unless I've restart my play app. Crazy!

Initially it looks like it's a problem of PlayMorphia, and I was thinking it is a PlayMorphia problem because I've just added an new feature allow processing @Converters annotation intelligently. I've tried to switch back to previous version and I found it's still there! And rewind to the version before previous version, it's even still there!

Finally I found it's caused by a recent updates to PlayRythm. Specifically the following code:

And the problem has gone when I changed it to 

So obviously I need to reconfigure the Rythm Engine in dev mode even when the engine has been configured and initialized during pre-compilation process.

This is very strange and I've still no idea on why it happens