Results 1 to 10 of 10

Thread: commiting the persistence context before reaching the end-state

  1. #1

    Default 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

  2. #2
    Join Date
    Jun 2008
    Posts
    16

    Default

    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!

  3. #3
    Join Date
    Oct 2008
    Posts
    13

    Default

    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.

  4. #4
    Join Date
    Jun 2008
    Posts
    16

    Default

    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.

  5. #5
    Join Date
    Sep 2009
    Posts
    26

    Default

    I have the same problem plz someone help us

  6. #6
    Join Date
    Aug 2005
    Location
    Germany, Frankfurt am Main
    Posts
    22

    Default

    did someone find a solution for this?

  7. #7
    Join Date
    Mar 2009
    Location
    Ajaccio, France
    Posts
    25

    Default

    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.

  8. #8
    Join Date
    Sep 2009
    Posts
    26

    Default

    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??

  9. #9
    Join Date
    Mar 2009
    Location
    Ajaccio, France
    Posts
    25

    Default

    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.

  10. #10
    Join Date
    Sep 2009
    Posts
    26

    Default

    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
  •