문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top