Jul 7th, 2008, 02:00 PM
commiting the persistence context before reaching the end-state
How do I commit the persistence context within webflow
before reaching the end state? The view-state elements don't have a commit attribute as the end-state element.
I know that you usually do not commit before ending the flow, but in my case I am dealing with a particular flow in which it is convenient to know that changes are committed to the database in a specific view.
I tried to solve this by calling a service method inside the flow. This indeed saves my data, but at the end of the flow
the same data is saved again. I have for example a collection. Objects added to the collection are thus saved 2 times (first in calling the service method, secondly at the end of the flow). This results in duplicate inserts.
Last edited by ivan2007; Jul 7th, 2008 at 02:11 PM.
Reason: more accurate
Nov 26th, 2008, 02:56 PM
I'm having the same issue. I need to commit before calling a remote service to operate on the data I just committed. Any way to commit mid-way in a flow with the persistence-context?
Dec 10th, 2008, 08:00 AM
I am on the same situation.
The only way I can think is to use subflow. Inside subflow, having a end-state to commit.
If anyone can find a better way, please let me know.
Dec 10th, 2008, 08:30 AM
I ended up passing the transaction manager into the service and committing that way:
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = txManager.getTransaction(def);
... make db changes...
Not nearly as elegant as @Transactional, but it does work.
Sep 30th, 2009, 04:18 PM
I have the same problem plz someone help us
Feb 15th, 2011, 05:25 AM
did someone find a solution for this?
Feb 16th, 2011, 01:15 PM
you can achieve this by calling a service method having a @Transactional(readonly = false) annotation....
the method may be empty... the idea is just to call it.
We provide a full example that does exactly this:
You can try it here: http://www.springfuse.com/quickstart
Feb 18th, 2011, 12:56 AM
Can you point us to the exact link please? because your link is about Springfuse tutorial.
i don't understand why an empty method would save the data??
Feb 18th, 2011, 02:05 AM
The link is correct, from there you can generate a full webapp.
You need to undertand how @Transactional work, the best is to read the doc:
The empty method does nothing of course. But the fact that it is annotated with @Transactional and that it is called outside of an existing transaction has an impact on the current persistence context (the one bound to the flow):
It starts a transaction, flush the persistence context and commit the transaction.
The key point it that when it flushes the persistence context, it flushes the entire persistence context, not only as you could wrongly assume, the modification that could have been made by the 'empty' method.
So in short, if the persistence context was 'dirty' before calling the empty method... then calling the method propagates the changes to the DB.