-
Jul 7th, 2008, 02:00 PM
#1
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
#2
Bump!
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?
Thanks!
-
Dec 10th, 2008, 08:00 AM
#3
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
#4
I ended up passing the transaction manager into the service and committing that way:
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.P ROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
... make db changes...
txManager.commit(status);
Not nearly as elegant as @Transactional, but it does work.
-
Sep 30th, 2009, 04:18 PM
#5
I have the same problem plz someone help us
-
Feb 15th, 2011, 05:25 AM
#6
did someone find a solution for this?
-
Feb 16th, 2011, 01:15 PM
#7
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
Nicolas.
-
Feb 18th, 2011, 12:56 AM
#8
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
#9
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:
http://static.springsource.org/sprin...ansaction.html
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.
-
Feb 18th, 2011, 06:38 PM
#10
Thx a lot for your reply.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules