codeconsole opened a new issue, #14511:
URL: https://github.com/apache/grails-core/issues/14511
```groovy
class User {
String id
static mapping = {
id generator: 'assigned'
}
}
```
```groovy
def graeme = new User()
graeme.id = 'graeme'
graeme.save(flush:true)
def user = User.get('graeme')
user.save(flush:true, insert:false) // results in BulkWriteError{index=0,
code=11000, message='E11000 duplicate key error collection ..
```
This is caused because there is no common session.
https://github.com/grails/grails-data-mongodb/blob/c8287aadad3777f308ff625096171c24f0eebaf4/grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoCodecEntityPersister.groovy#L186-L188
https://github.com/grails/grails-data-mongodb/blob/c8287aadad3777f308ff625096171c24f0eebaf4/grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoCodecEntityPersister.groovy#L255-L257
returns false because `session.contains(obj)` returns **false**
The following resolves the situation, but it is not intuitive.
```groovy
User.withSession {
def user = User.get('graeme')
user.save(flush:true, insert:false)
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]