tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bertrand Guay-Paquet <ber...@step.polymtl.ca>
Subject Re: How can I catch OptimisticLockException?
Date Mon, 29 Oct 2012 14:50:32 GMT
Hi,

I had something to this effect in my "todo list":
http://blog.vacs.fr/index.php?post/2010/06/27/Fault-tolerant-EJB-interceptor%3A-a-solution-to-optimistic-locking-errors-and-other-transient-faults

It's an interceptor which catches exceptions. You could use it to 
rethrow your own exception when an optimistic lock exception occurs.

disclaimer: I haven't tried it yet.

Bertrand

On 29/10/2012 7:47 AM, Jean-Louis MONTEIRO wrote:
> There is no trivial way to get that in the client cause the spec requires
> it to be wrapped.
> As the exception is thrown during commit (flush at least), you can in the
> business method (ie. the session bean method) force a em.flush() to
> propagate the persistence context to the database and get all relational
> constraints validated by the database.
> Around the flush statement, you can catch the Optimistic Lock exception and
> throw a business exception.
>
> That's the best way from a design point of view to do and to deal with such
> a situation.
>
> Jean-Louis
>
>
> 2012/10/29 Romain Manni-Bucau <rmannibucau@gmail.com>
>
>> hi,
>>
>> can you share the whole stack please?
>>
>> *Romain Manni-Bucau*
>> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
>> *Blog: **http://rmannibucau.wordpress.com/*<
>> http://rmannibucau.wordpress.com/>
>> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
>> *Github: https://github.com/rmannibucau*
>>
>>
>>
>>
>> 2012/10/29 knak55 <KNakagawa@pngjudiciary.gov.pg>
>>
>>> Hi,
>>>
>>> I am trying to migrate an application which works on Glassfish 3.1.2.2to
>>> TomEE 1.5.
>>> The application calls each component like this :  JSF -> CDI -> Stateless
>>> EJB -> JPA -> DB
>>> On the Glassfish, a program(CDI) in the web tire can handle the
>>> “OptimisticLockException” with the following code successfully.
>>>
>>>          :
>>> } catch  (Exception e) {
>>>          if (e.getCause() instanceof
>>> javax.persistence.OptimisticLockException) {
>>>          :
>>>
>>> However, on the TomEE 1.5,  we got javax.transaction.RollbackException
>>> instead of
>>> javax.persistence.OptimisticLockException.
>>>
>>> How can I catch “OptimisticLockException” in the CDI?
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>>
>> http://openejb.979440.n4.nabble.com/How-can-I-catch-OptimisticLockException-tp4658313.html
>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>


Mime
View raw message