ripper234
ripper234

Reputation: 230058

How can I handle DB connectivity errors in Play 1.X?

I am writing a status page, that checks various system services and renders their status.

As part of my testing, I'm shutting down my database, and would like to test whether it's working or not, and render this fact on the page.

However, when the database is shut down, I can't seem to render any page - instead, I get this error before my code is run:

org.hibernate.exception.GenericJDBCException: Cannot open connection

Play is trying to open a transaction, fails, and kills my entire page.

How can I work around this for this specific page, manually test my DB connection, and act accordingly, instead of failing the entire page?

Upvotes: 3

Views: 239

Answers (1)

Seb Cesbron
Seb Cesbron

Reputation: 3833

Use the @NoTransaction annotation on your controller method to avoid opening a transaction

Upvotes: 1

Related Questions