0

So our app has like 10,000 different DAO classes using multiple session factories and data sources. The data sources use c3p0 for connection pooling and we use hibernate framework to talk to an oracle database.

Now, when we have database errors like if the server is down, max connection attempts reached etc... We want to log them using our own logging mechanism basically do xxx.fatal("Database server down", e).

Question 1: How do I catch these exceptions? (Database server down, max connection attempts reached etc...)?

Question 2: How do I log by making minimal code changes? Can I use hibernate interceptor for this?

Please advise.

Thanks

Rtn9
  • 101
  • 10

1 Answers1

0

Use Spring AOP and create an afterthrowing advice to catch exceptions and log them. Have a look at this for an example.

Ean V
  • 5,091
  • 5
  • 31
  • 39
  • Thanks Ean for ur reply. I started implementing this approach but I keep getting the error org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class – Rtn9 Oct 14 '13 at 17:37
  • Complete error is this Could not generate CGLIB subclass of class [class org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser$AuthenticationManagerDelegator]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser$AuthenticationManagerDelegator – Rtn9 Oct 14 '13 at 17:56
  • This should be related to your Spring's config. If you are using CGLIB as proxy provider, you need to enable it in configuration. I guess this is the problem (but not sure) ;) – Ean V Oct 14 '13 at 22:55
  • My pointcut was using all the public methods and inturn was using a method from a jar and failing. Once I changed my pointcut I am not seeing the error anymore. I however am not getting the control to the aspect I have defined. I will post it in a diff question. Thanks a lot – Rtn9 Oct 15 '13 at 16:42
  • I have added the problem I am facing using the @AfterThrows Advice in a seperate theread here http://stackoverflow.com/questions/19386858/spring-aop-afterthrowing-advice-not-being-executed – Rtn9 Oct 15 '13 at 19:31
  • A little bit busy today but will have a look at that one as well ;) – Ean V Oct 15 '13 at 22:52