Search code examples
playframeworkmorphiamlab

playMorphia with mongoLAB IllegalStateException: can't call authenticate twice on the same DBObject


My Play! application has one module, morphia. My DB is mongolab (on AWS). It compiles and runs the first time. Then will throw this DB authenticate exception an all subsequent requests. Does anyone know if playmorphia tries to re-authenticate on every request? Any help much appreciated. Thanks.

Caused by: java.lang.IllegalStateException: can't call authenticate twice on the same DBObject
    at com.mongodb.DB.authenticate(DB.java:437)
    at play.modules.morphia.MorphiaPlugin.initMorphia_(MorphiaPlugin.java:368)
    at play.modules.morphia.MorphiaPlugin.onApplicationStart(MorphiaPlugin.java:444)
    at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:480)
    at play.Play.start(Play.java:515)

Solution

  • Well, db authentication is called on play start. The problem is when you are run in dev mode, play might restart on every code change in your java source and view source.

    I've never encountered this problem before coz I've always using mongodb in a trusted environment. But this kind of issue should be avoid, probably simply try/catch and ignore. Could you please submit an issue to https://github.com/greenlaw110/play-morphia/issues/new ?