开发者

How do I configure Hibernate to fail startup if database is down?

开发者 https://www.devze.com 2023-02-12 07:03 出处:网络
I\'m using hibernate+spring (but I had the same problem with hibernate alone). When the app starts up, hibernate says it is building a session factory. The fact is that even if the db is down (in my c

I'm using hibernate+spring (but I had the same problem with hibernate alone). When the app starts up, hibernate says it is building a session factory. The fact is that even if the db is down (in my case mysql), hi开发者_如何学Pythonbernate doesn't fail, it just starts up without even an exception. I'd like it to fail, is there a way to do that in the config?


If you are using a connection pool (c3p0 for example), it verifies the connection and fails on startup. Look here for a how-to

You can also use hibernate.hbm2ddl.auto=validate - its main purpose is to validate whether the structure of the schema matches the entities, but it means that hibernate will attempt a connection, and throw an exception if it fails.

0

精彩评论

暂无评论...
验证码 换一张
取 消