title: JPA (and/or Hibernate) - How to set timeout threshold for connection and/or query?
body: <p>I'm trying to figure out how to configure my project such that JPA will timeout and throw an exception after a configured amount of time. There are two situations where I would like this to happen:</p>
  
  <ul>
  <li>When JPA is unable to even connect to the database</li>
  <li>When a JPA query takes longer than the timeout threshold to return a result set</li>
  </ul>
  
  <p>I'm not sure if these two scenarios can be configured separately (a different timeout threshold for each), or if one threshold is used for both.</p>
  
  <p>My project is currently set up as follows:</p>
  
  <ul>
  <li>Coding to the JPA 2.0 specification</li>
  <li>Using Hibernate 3.5.6 as the JPA implementation</li>
  <li>Using c3p0 connection pooling with Hibernate</li>
  <li>Using <code>persistence.xml</code> configuration file (using Hibernate-specific property values only when necessary)</li>
  <li><strong>NOT</strong> using any Hibernate-specific configuration files</li>
  </ul>