MongoDB Plugin
  1. MongoDB Plugin
  2. GPMONGODB-194

NullPointerException at org.grails.datastore.mapping.mongo.engine.MongoEntityPersister.checkVersion(MongoEntityPersister.java:571)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0.RC4, 1.0.0.RC5
    • Fix Version/s: 1.0.0.GA
    • Labels:
    • Environment:
      Grails 2.0.1, Os X 10.6.8, MongoDB 2.0.3, Java 1.6.0_29
    • Testcase included:
      yes

      Description

      Just checked out the latest source and built the RC5 plugin, as there seems to be an issue with the plug-in management. The plug-ins latest version is still RC4, even it is listed as RC5 in the overview.
      I am still encountering the same exception in RC5 as in RC4. http://jira.grails.org/browse/GPMONGODB-190
      I am attaching a new integration test, which uses a service and is easier to reproduce. running grails test-app should reproduce the issue every time.

      This is the stacktrace:

        java.lang.NullPointerException
      	at org.grails.datastore.mapping.mongo.engine.MongoEntityPersister.checkVersion(MongoEntityPersister.java:589)
      	at org.grails.datastore.mapping.mongo.engine.MongoEntityPersister$5.doInDB(MongoEntityPersister.java:542)
      	at org.grails.datastore.mapping.mongo.engine.MongoEntityPersister.updateEntry(MongoEntityPersister.java:533)
      	at org.grails.datastore.mapping.mongo.engine.MongoEntityPersister.updateEntry(MongoEntityPersister.java:59)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister$2.run(NativeEntryEntityPersister.java:726)
      	at org.grails.datastore.mapping.core.impl.PendingOperationExecution.executePendingOperation(PendingOperationExecution.java:33)
      	at org.grails.datastore.mapping.core.AbstractSession.flushPendingOperations(AbstractSession.java:323)
      	at org.grails.datastore.mapping.core.AbstractSession.flushPendingUpdates(AbstractSession.java:302)
      	at org.grails.datastore.mapping.core.AbstractSession.flush(AbstractSession.java:240)
      	at org.grails.datastore.mapping.mongo.MongoSession.flush(MongoSession.java:113)
      	at org.grails.datastore.mapping.transactions.DatastoreTransactionManager.doCommit(DatastoreTransactionManager.java:156)
      	at mongotest.IntegrationTests.test2(IntegrationTests.groovy:60)
      

      This is probably being caused by an incorrect DBRef.
      The Comment Class has a belongsTo property

      static belongsTo = [user:User]
      

      The mongodb looks as following:

      
      > db.posting.find()
      { "_id" : ObjectId("4f889d640364d75c83cb2518"), "title" : "1st Posting", "user" : { "$ref" : "user", "$id" : ObjectId("4f889d630364d75c83cb2516") }, "version" : NumberLong(1), "comments" : [ 	{ 	"dateCreated" : ISODate("2012-04-13T21:40:53.238Z"), 	"text" : "1st Comment", 	"user" : {
      		"$ref" : "comment",
      		"$id" : ObjectId("4f889d630364d75c83cb2516")
      	}, 	"version" : null } ] }
      > db.user.find()
      { "_id" : ObjectId("4f889d630364d75c83cb2514"), "name" : "John", "version" : 0 }
      { "_id" : ObjectId("4f889d630364d75c83cb2515"), "name" : "Paul", "version" : 0 }
      { "_id" : ObjectId("4f889d630364d75c83cb2517"), "name" : "Paul", "version" : 0 }
      { "_id" : ObjectId("4f889d630364d75c83cb2516"), "name" : "John", "version" : NumberLong(1) }
      

      The 'comment' Document contains the comment, which has a reference to the user with ObjectId "4f889d630364d75c83cb2516". "4f889d630364d75c83cb2516" is a valid user. However, the $ref points to the 'comment' Document instead of the 'user' Document.

      This furthermore shows, that the Comments id property is not persisted. There already is an issue for this http://jira.grails.org/browse/GPMONGODB-158

      I also noticed that the dateCreated field of an embedded document is not automatically populated. However, it is possible to get around that issue by just initializing the Date manually, which I have done in the Comment Domain class.

        Activity

        Hide
        Narek Kalvans added a comment -

        I had the same problem. I have a User collection. and I saw that the users created ufter plugin upgrade have 'version' field. and old ones don't. I added a field named 'version' with value 0 in my collection and the problem seems to fixed. I don't now what is that field for yet. Didn't find any documantation.

        Show
        Narek Kalvans added a comment - I had the same problem. I have a User collection. and I saw that the users created ufter plugin upgrade have 'version' field. and old ones don't. I added a field named 'version' with value 0 in my collection and the problem seems to fixed. I don't now what is that field for yet. Didn't find any documantation.
        Show
        Graeme Rocher added a comment - fixed by https://github.com/SpringSource/grails-data-mapping/commit/350ebc78cd2fdf08774a726610fd50617f65a951

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            St.H
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: