admin管理员组文章数量:1316376
We have recently upgraded to Grails 6.2.3 from 5.2 etting exception when new user is being added to our application and following is the stack trace for the same.
Caused by: .springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [***.Person#101211]; nested exception is .hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [**.**.**.Person#101211]
at .springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:230)
at .grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:717)
at .grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:301)
at .grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:241)
at .grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:120)
at .grails.orm.hibernate.AbstractHibernateGormInstanceApi.performSave(AbstractHibernateGormInstanceApi.groovy:247)
at .grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:164)
at .grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:153)
at **.**.**.ProdUserService.$tt__createUser(ProdUserService.groovy:72)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at grails.gorm.transactions.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:94)
at .springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at grails.gorm.transactions.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:91)
at **.**.**.UserController.save(UserController.groovy:158)
Following is the code snippet
Controller class:
def save(){
def userData = new JsonSlurper().parseText(params.userData)
//business logic, some validations
//call to produserservice
CreateUserDTO createUserDTO = prodUserService.createUser(userData, user)
//business logic
Service class:
CreateUserDTO createUser(Map params, ProdUser user) {
ProdUser userInst = new ProdUser()
grailsWebDataBinder.bind userInst, new SimpleMapDataBindingSource(params)
Person person = userInst.person
//business logic - assigning values to person like person.prop1 = userInst.prop1
person.save(failOnError: true) //getting error here!
userInst.save(flush: true, failOnError: true)
new CreateUserDTO(prodUser: userInst, prodUserStatus: prodUserStatus)
Getting error on person.save()
Things to note:
Person and ProdUser are domain classes having parent-child relationship i.e. person BelongsTo ProdUser
There are no code changes around this. This stopped working post upgrade to grails6.
Do I need to update any specific configuration or modify any implementation? Is there any specific order in which save() should be called in case of belongTo relationship.
I tried using merge(), clearing the session but didn't solve the issue.
本文标签: Getting orgspringframeworkdaoDuplicateKeyException after upgrading to Grails 623Stack Overflow
版权声明:本文标题:Getting org.springframework.dao.DuplicateKeyException after upgrading to Grails 6.2.3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742002276a2411253.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论