1. start a nested conversation and set em flush mode to manual before showing popup.
@Begin(nested = true, flushMode = FlushModeType.MANUAL)
public void prepareEdit() {}
2. when click save button, end conversation and flush em.
@End
public void saveEdit() {
xxxService.update(WhatEverObjectYouAreEditing);
dbHelperService.flush();
// If the current object needs to updated on session scope, raise event
Events.instance().raiseEvent(eventName, WhatEverObjectYouAreEditing)
// Then the parent action should listen to the eventName, so the object can be reloaded.
}
3. when click cancel button, end conversation and refresh data
@End
public void cancel() {
dbHelperService.refresh(WhatEverObjectYouAreEditing);
}
Couple of things to remember
1. Conversation vs Transaction
- Transaction is not started when conversation starts
- You can only specify transaction will be maintained manually when conversation starts. (That definition will be cleared when conversation ends)
- Transaction will be committed when you execute.
- When transaction ends, dirty object will be cleared if not commited.
2. Flush vs Commit
- When executing a method, you can flush any time.
- Flush updates database to reflect the changes in objects in memory.
: However, it is still not committed yet.
: Unless flushes, database will not see the change.
- When the execution ends, transaction will be commited automatically.
- You can run flush, but cannot run commit
Showing posts with label seam. Show all posts
Showing posts with label seam. Show all posts
10/21/2010
Seam: Manual Transaction
Subscribe to:
Posts (Atom)