Вопрос

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