Announcement Announcement Module
Collapse
No announcement yet.
commiting the persistence context before reaching the end-state Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 02:11 PM. Reason: more accurate

  • #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!

    Comment


    • #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.

      Comment


      • #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.

        Comment


        • #5
          I have the same problem plz someone help us

          Comment


          • #6
            did someone find a solution for this?

            Comment


            • #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.

              Comment


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

                Comment


                • #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.

                  Comment


                  • #10
                    Thx a lot for your reply.

                    Comment

                    Working...
                    X