9 Replies Latest reply on Feb 1, 2007 3:55 AM by Gavin King


    jk;l jkl; Expert

      I have a versioned object for which I'd like an error message to show up when an OptimisticLockException occurs. Adding an entry to exceptions.xml doesn't do anything because, though the OLE is thrown as seen in the log, it's subsequently caught by something.

      I'm not merging the object in an action method, however. The update to the object simply occurs as the result submitting a form with an inputText that is bound to a property on the versioned object.

      When I submit the form bound with an out-of-date object, the exception is thrown but there's no output on the page to indicate so because the OLE doesn't reach out of the Seam layer to exceptions.xml.

      How can I solve this? I'd think it'd be common enough that the JBoss forums would have some insight, but nothing is there on this issue!

      I think I could have an action method and catch the exception there, but then I'd need the additional method, which would just do a merge(). And then I'm not taking advantage of the SMPC with its mergeless updates! (But this probably applies to EXTENDED PCs too...)

        • 1. Re: OptimisticLockException
          Pete Muir Master

          As mentioned in the manual, @Redirect and @Render don't work for certain phases of the JSF lifecycle. WHich are you using?

          • 2. Re: OptimisticLockException
            jk;l jkl; Expert

            I was using @Render, I'll try using @Redirect instead. I'm guessing @Render would've been preferrable so that the error appears on the same page rather than (like a FacesMessage from an invalid field)

            Why do @Render (only in INVOKE_APPLICATION) and @Redirect (not in RENDER_RESPONSE) not work at any time in the request lifecycle? Can't redirects and forwards happen at any time? (I'm sure there's a good reason, maybe someone could explain.)

            • 3. Re: OptimisticLockException
              Gavin King Master

              Nope, as soon as you do something to the servlet response object, you can't change your mind later and do something else.

              However, I don't quite recall why I decided that you couldn't use @Render during the PROCESS_VALIDATIONS and UPDATE_MODEL_VALUES phases. There was probably some reason why this didn't work, but its possibly an oversight. Perhaps you want to experiment with the changing the Seam code and see if I got this wrong....

              • 4. Re: OptimisticLockException
                jk;l jkl; Expert

                Changing exceptions.xml to redirect from render doesn't do anything - same problem. This exception is getting caught somewhere and not propagating to a point where exceptions.xml can do anything with it.

                What am I supposed to do here? (Short of creating an action method - see my OP.)

                • 5. Re: OptimisticLockException
                  jk;l jkl; Expert

                  In the log, the OptimisticLockException (OLE) shows up somewhere between the following two statements:

                  [SeamPhaseListener] after phase: INVOKE_APPLICATION(5)
                  #Several other statements here
                  #The exception stack traces followed immediately by the next line:
                  [SeamPhaseListener] before phase: RENDER_RESPONSE(6)

                  Also, the OLE is caused by a org.hibernate.StaleObjectStateException. The OLE causes org.jboss.tm.JBossRollbackException which then causes java.lang.IllegalStateException. I try catching all of them in exceptions.xml, but none of them work!

                   <exception class="org.hibernate.StaleObjectStateException">
                   <redirect>optimistic lock exception</redirect>

                  • 6. Re: OptimisticLockException
                    jk;l jkl; Expert

                    Is my only option then to use an action method? It seems like an ugly solution but the only thing I can think of...am I missing any possibilities?

                    • 7. Re: OptimisticLockException
                      jk;l jkl; Expert

                      In cases like this where an OptimisticLockException occurs, does Seam have no way of using exceptions.xml to handle this fact and display a nice error message?

                      I've exhausted all my resources and don't know where else to turn apart from this board...please, if somebody knows how to use exceptions.xml to catch it, let me know...

                      If you need any more info on the issue, I can provide it...


                      • 8. Re: OptimisticLockException
                        Gavin King Master

                        Nope, Seam cant do much about exceptions which occur at this point. As I've said here many times, JSF exception handling sucks ass, your only option is to beg for proprietary features from the JSF implementations.

                        If you read the JSF spec, it actually says explicitly that JSF implementations should swallow and ignore exceptions that occur in phase listeners.

                        • 9. Re: OptimisticLockException
                          Gavin King Master

                          Actually, that's not quite right. There probably is something we can do to allow these exceptions to be handled in exceptions.xml. Will be messy, but possible.