With the entityManagerFactory you can only get a EntityManager and send a check query to the DB, but in this case I think the best solution is to configure your connection pool with a validator.
In this way each connection created or retrieved from the pool is validated via JDBC API or with a simple query.
For example, in JBoss inside the data-source configuration you can add the following lines:
<!-- sql to call when connection is created -->
<new-connection-sql>some arbitrary sql</new-connection-sql>
<!-- sql to call on an existing pooled connection when it is obtained from pool -->
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
or (for Postgres, but there are example for each DBMS)
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter>
</validation>