Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 1.0.1
-
Fix Version/s: 1.0.2
-
Component/s: None
-
Labels:None
-
Environment:Grails 1.0.1, Groovy 1.5.4, Java 1.5 update 12
-
Testcase included:yes
Description
Following up on a mail to user@grails.codehaus.com entitled merge() fails on LazyInitializationException
I am unable to merge() a persistent object stored in the session. When doing so, it fails on a LazyInitializationException.
The merge() is done inside a transactional service method, but the same behavior occurs when merging from the controller.
I have attached a simple projet that duplicates the problem.
- Click on the QuestionController link
- Select a question from the drop down
- Click "Next"
- Click "showTheBug" . You will have a stack trace.
Attachments
-
$i18n.getText("admin.common.words.hide")
- BugProof.zip
- 04/Mar/08 1:28 PM
- 250 kB
- Vincent Giguère
-
- BugProof/.classpath 6 kB
- BugProof/.project 0.5 kB
- BugProof/application.properties 0.1 kB
- BugProof/BugProof.iml 2 kB
- BugProof/BugProof.ipr 14 kB
- BugProof/BugProof.iws 37 kB
- BugProof/BugProof.launch 2 kB
- BugProof/BugProof.tmproj 2 kB
- BugProof/build.xml 1 kB
- BugProof/grails-app/.../BootStrap.groovy 0.4 kB
- BugProof/grails-app/conf/Config.groovy 3 kB
- BugProof/grails-app/.../DataSource.groovy 0.8 kB
- BugProof/grails-app/.../hibernate.cfg.xml 0.4 kB
- BugProof/grails-app/.../resources.groovy 0.0 kB
- BugProof/grails-app/.../UrlMappings.groovy 0.2 kB
- BugProof/.../QuestionController.groovy 0.5 kB
- BugProof/grails-app/.../messages.properties 2 kB
- BugProof/.../messages_de.properties 3 kB
- BugProof/.../messages_es.properties 3 kB
- BugProof/.../messages_fr.properties 2 kB
- BugProof/.../messages_it.properties 2 kB
- BugProof/.../messages_ja.properties 2 kB
- BugProof/.../messages_nl.properties 3 kB
- BugProof/.../messages_ru.properties 4 kB
- BugProof/.../messages_th.properties 5 kB
- BugProof/.../messages_zh_CN.properties 2 kB
- BugProof/.../QuestionService.groovy 0.2 kB
- BugProof/grails-app/views/error.gsp 1 kB
- BugProof/grails-app/.../layouts/main.gsp 0.7 kB
- BugProof/grails-app/.../question/modify.gsp 0.5 kB
-
$i18n.getText("admin.common.words.hide")
- BugProof2.zip
- 04/Mar/08 2:46 PM
- 254 kB
- Vincent Giguère
-
- BugProof/.classpath 6 kB
- BugProof/.project 0.5 kB
- BugProof/application.properties 0.1 kB
- BugProof/BugProof.iml 2 kB
- BugProof/BugProof.ipr 14 kB
- BugProof/BugProof.iws 37 kB
- BugProof/BugProof.launch 2 kB
- BugProof/BugProof.tmproj 2 kB
- BugProof/build.xml 1 kB
- BugProof/grails-app/.../BootStrap.groovy 0.3 kB
- BugProof/grails-app/conf/Config.groovy 3 kB
- BugProof/grails-app/.../DataSource.groovy 0.6 kB
- BugProof/grails-app/.../resources.groovy 0.0 kB
- BugProof/grails-app/.../UrlMappings.groovy 0.2 kB
- BugProof/.../QuestionController.groovy 0.5 kB
- BugProof/grails-app/domain/Answer.groovy 0.0 kB
- BugProof/grails-app/.../Question.groovy 0.1 kB
- BugProof/grails-app/.../messages.properties 2 kB
- BugProof/.../messages_de.properties 3 kB
- BugProof/.../messages_es.properties 3 kB
- BugProof/.../messages_fr.properties 2 kB
- BugProof/.../messages_it.properties 2 kB
- BugProof/.../messages_ja.properties 2 kB
- BugProof/.../messages_nl.properties 3 kB
- BugProof/.../messages_ru.properties 4 kB
- BugProof/.../messages_th.properties 5 kB
- BugProof/.../messages_zh_CN.properties 2 kB
- BugProof/.../QuestionService.groovy 0.3 kB
- BugProof/grails-app/views/error.gsp 1 kB
- BugProof/grails-app/.../layouts/main.gsp 0.7 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
The bug can also be reproduced when working with entities mapped in GORM.
I have changed the JPA/Hibernate annotated java classes and moved them to grails-app/domain. I experience the same behavior.
Please see BugProof2.zip
The merge() method has been changed to return the new merged instance, so you have to write code like this:
def b = book.merge()
There is an argument that maybe this should be a static method, if there is a massive outcry we can make a static version of the method
I'm not sure how much this affects this particular problem, but I'm getting a NonUniqueObjectException "a different object with the same identifier value was already associated with the session" when it gets to the session.lock() call in MergePersistentMethod. merge() doesn't update the entity parameter, it returns the updated instance, so
session.merge(target);
session.lock(target, LockMode.NONE);
...
return target;
should be
Object merged = session.merge(target);
session.lock(merged, LockMode.NONE);
...
return merged;
but this wouldn't work for Grails since it's an instance method.