Uploaded image for project: 'Hibernate OGM'
  1. OGM-1222

Duplicate insert on mutate within entitymanager lifecycle


    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Cannot Reproduce
    • Affects versions: 5.1.0.Alpha1, 5.1.0.Beta1
    • Fix versions: 5.4.0.Beta2
    • Components: mongodb
    • Labels:
    • Environment:
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
    • Sprint:


      Note: I'm no expert at hibernate.

      It seems like hibernate will try to reinsert a document if you mutate it at any point within a single entity managers lifetime. That means that from the time you persist an object, to calling em.close, you can not mutate that object.

      The exception is a "com.mongodb.DuplicateKeyException"

      After looking around a bit it looks to me like it's due to reusing the same "sharedTuple" without overwriting the tuple method, even after flushing the object. That means that the tuple keeps sicking around as an "INSERT" tuple, which gets reinserted into the action queue on update, causing a double insert. All other parts of the stack seem aware that it's actually a partial update, they just never change the method on the tuple.

      I've attached a test class that demonstrates how it works and doesn't. I've tested it on OGM - 5.0.3.Final, where it seems to work fine. Please do note that it assumes a mongodb server running on localhost:27017, and the database "test" WILL BE DROPPED.




            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: