openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From is_maximum <mnr...@gmail.com>
Subject Re: how do you manage db exceptions?
Date Sun, 30 Nov 2008 06:19:32 GMT

Judes,
The first approach seems to be very nice. I like it :) 
but can you tell me how can I write an simple observer to notify an object
that say, SQLException has been thrown? I know the observer pattern but what
I can't understand is that because SQLException is not my object so I can't
handle it. As far as I know I have to extend it from say, java Observable
class. maybe I can manage it using Proxy I don't know. Would you give me
more information on this?

thanks 



Judes Tumuhairwe wrote:
> 
> It depends.
> - If you're hand coding everything yourself, I would suggest some kind of
> observer-listener approach where you listen for specific the exceptions &
> take the necessary action. If you're using a framework like JBoss Seam,
> for
> example, this can be done declaratively (application wide). I'm sure
> Spring[1] and other frameworks have some kind of implementation of that
> design pattern.
> 
> - The other (less elegant) option is to  try/catch all 8 exceptions in the
> JPA (EntityExists, EntityNotFound, OptimisticLock, NoResult,
> TransactionRequired, etc. etc.) in the webMethod of your web-service (or
> the
> ExceptionInterceptor in as it may be) and tell the client what happened.
> Obviously this assumes that the persistence-manager didn't change/wrap the
> exception.
> 
>> the only way to make this that comes to my mind is to catch the exception
>> and look for some keyword exception in the stack trace and then find out
>> what is the cause
> The bad news is OpenJPA has its own exceptions [e.g.
> ObjectNotFoundException
> instead of javax.persistence.EntityNotFoundException]; the good news is
> you
> can just catch their parent StoreException and call getType()
> 
> [1]
> <http://docs.huihoo.com/jboss/seam/2.0.0.GA/reference/en/html/events.html#d0e4460>
> http://www.theserverside.com/tt/articles/article.tss?l=SpringLoadedObserverPattern
> 
> Judes
> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/how-do-you-manage-db-exceptions--tp1591722p1594437.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message