10 Replies Latest reply on Dec 18, 2006 5:10 AM by pmuir

    Does anyone use @Rollback?

    gavin.king

      I'd like to know if anyone finds @Rollback to be really useful. I'm wondering if it is actually a stupid feature and should be deprecated, and replaced by an easy way to inject UserTransaction into JavaBean components.

      I need feedback on this.

      Thanks,
      Gavin

        • 1. Re: Does anyone use @Rollback?

          I wasn't aware that it existed. The more control of UserTransaction that's possible, the better -- though I imagine anyone using UserTransaction is probably already controlling it through code and not declaratively, so injection would probably suffice.

          • 2. Re: Does anyone use @Rollback?
            paulie!

            G'day

            I do use it, but I will let you decide if the UserTransaction stuff would be better.

            I use it probably out of a bit of laziness, I will try and explain: I have an Entity (lets call it mum) which I also use as a backing bean for a form. it has a collection of objects (Entity as well) on it (lets call each one a kid).

            Now On the form I have a button which calls an action to add another new (blank) Kid to the list so that the details of a new Kid can be filled in, I also have a delete button to remove a Kid. Now in the basic case if I click on the add or delete the associated action (in a SFSB) causes the injected Backing bean to get saved to the DB (as it is an Entity). But I only want the data saved IF they press the done button, this is so when they press Cancel nothing would have changed, even if they added or deleted Kids before hitting Cancel..

            So the add and delete methods both use @Rollback. This allows the new entries to be added to the list and the data in the backing bean to be updated but it will not be flushed to the DB unless the Done action is called which Doesn't have a @Rollback on it.

            As it is a very simple data entry problem I went with the Entity being re-used as a backing bean (I mentioned me being lazy). An easy workaround if Rollback wasn't there would be to use seperate backing beans ands entities, and use a bit of code to copy the backing dean data to the entry on the done action (I use this in all my more complicated forms). I also assume there is a way to control the transactions to do what I do without @Rollback, but using it means I only need the one annotation to get the desired result, so as you can imaging the code to do the above is very simple and sparse.

            Cheers

            Paul.

            • 3. Re: Does anyone use @Rollback?
              gavin.king

              This is NOT the right way to implement atomic conversations! You are supposed to either do your work outside a transaction, or use @Begin(flushMode=FlushMode.MANUAL).


              I didn't hear from anyone else who uses @Rollback yet....

              • 4. Re: Does anyone use @Rollback?
                paulie!

                 

                "gavin.king@jboss.com" wrote:
                This is NOT the right way to implement atomic conversations! You are supposed to either do your work outside a transaction, or use @Begin(flushMode=FlushMode.MANUAL).


                Wow I got an exclamation mark! AND capitals! We have been using Seam for a year now and have good chunk of code in production etc. So when Seam 1.0.1GA came out we decided to only upgrade when stable releases come out. Becaue of this it doesn't look like we can use the flushmode (although it is perfect for this) at the time I searched the doco and javadoc and couldn't come up with anything. So I tried using @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED), which didn't change a thing, the lists were still getting persisted. At that point I had too much other work to do so I used the above Hack (and hack it certainly is).

                So this leads me to asking if I can get an example of how to implement the "atomic conversation" pattern with Seam 1.0.1GA. If it is indeed to use TransactionAttribute then obviously I missed something and need to revisit my code.

                Bit of a thread hijack I know, but no-one seems to be posting here.


                • 5. Re: Does anyone use @Rollback?
                  m_hess

                  We are acutally using it as well.

                  We tend to do some of the more complex validations in our actionmethods, and if they fail it´s quite convinient to just give a specific outcome to rollback everything. I must admit though, that I don't know anything about UserTransaction (yet), so maybe this is considered a big DON'T (yes, with capitals :-) ), or antipattern.

                  • 6. Re: Does anyone use @Rollback?
                    wsollers

                    I use @Rollback the same.

                    Though I am not at all attached to it.

                    • 7. Re: Does anyone use @Rollback?
                      gavin.king

                      Yes, this use is the intended use, and is perfectly fine - but only as long as you dont use an extended persistence context.

                      (I still havn't made up my mind on this one.)

                      • 8. Re: Does anyone use @Rollback?
                        ccurban

                        That's the way I would use @Rollback too.
                        The problem is that the I have no chance of state refreshing after the rollback.

                        Actually I have got a page which displays a list of customers and one customer in detail, so that I can create, update and delete customers on one page.
                        The update could lazily consist of a delete and an insert, and a rollback in case there are business rules that prevent an insert.
                        As I have also to refresh the list in the transaction I run into the problem, that the list is wrong in case of a rollback.

                        Regards,
                        Christian

                        • 9. Re: Does anyone use @Rollback?
                          jovijojo

                          i am not using @rollback at all, enough problem trying to make seam work.
                          i think jboss seam team should put up some sort of general/common errors and their solusions, since apparently there are a number of them.

                          • 10. Re: Does anyone use @Rollback?
                            pmuir

                            You should see the SeamProblemsFAQ http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamProblemsFAQ.

                            I'm sure it's missing stuff, is there anything you can think of that should go on there?