Last week we ran into a problem in the large Java system, Hibernate. Our MySQL database database (hosted on Amazon RDS) did not respond for 5-10 minutes (it will still accept connections, but due to hardware problems, write throughput has dropped to zero). This piece of code:
getSession().save(entity); //session is an instance of org.hibernate.Session
Completion hangs about 8.5 minutes. It is so clear that this statement requires some kind of timeout condition so that it fails in the case of my specific scenario. I cannot guarantee that in the future I will not see a similar hardware problem.
I should mention that I'm still pretty new to Hibernate, so it's possible that I just don't understand some things, such as the relationship between using save() and using criteria, transactions, etc. So I found the following:
hibernate.c3p0.timeout can be used to set connection timeouts in the C3P0 connection pool.getSession().getTransaction().setTimeout(...) can be used to turn off a transactiongetSession().createQuery(...).setTimeout(...) can be used for request timeout- I saw JPA 2
javax.persistence.query.timeout , but I'm not quite sure what I want (I also don't think my version of Hibernate is new enough)
None of this looks like what I want to do (except maybe JPA 2). It seems to be very simple. Is something missing here?
Thanks!
Brent nash
source share