We're updating the issue view to help you get more done. 

Duplicate insert on mutate within entitymanager lifecycle

Description

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.

Environment

JPA

Status

Assignee

Viet Nguyen

Reporter

Jesper Jensen

Labels

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

5.1.0.Alpha1
5.1.0.Beta1

Priority

Critical