Issue Details (XML | Word | Printable)

Key: GRAILS-2586
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Graeme Rocher
Reporter: Vincent Giguère
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Grails

merge() fails on LazyInitializationException - Example attached

Created: 04/Mar/08 01:28 PM   Updated: 13/Mar/08 07:30 AM   Resolved: 13/Mar/08 07:30 AM
Component/s: None
Affects Version/s: 1.0.1
Fix Version/s: 1.0.2

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive BugProof.zip (250 kB)
2. Zip Archive BugProof2.zip (254 kB)

Environment: Grails 1.0.1, Groovy 1.5.4, Java 1.5 update 12

Testcase included: yes


 Description  « Hide

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.


Burt Beckwith added a comment - 04/Mar/08 02:32 PM

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.


Vincent Giguère added a comment - 04/Mar/08 02:45 PM

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


Graeme Rocher added a comment - 13/Mar/08 07:30 AM

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