Java Code Examples for javax.persistence.EntityManagerFactory.unwrap()

The following are Jave code examples for showing how to use unwrap() of the javax.persistence.EntityManagerFactory class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: micrometer   File: HibernateMetrics.java   Source Code and License Vote up 7 votes
/**
 * Get the {@code Statistics} object from the underlying {@code SessionFactory}. If it isn't hibernate that is
 * used return {@code null}.
 *
 * @param emf an {@code EntityManagerFactory}
 * @return the {@code Statistics} from the underlying {@code SessionFactory} or {@code null}.
 */
private Statistics getStatistics(EntityManagerFactory emf) {
    try {
        SessionFactory sf = emf.unwrap(SessionFactory.class);
        return sf.getStatistics();
    } catch (PersistenceException pe) {
        return null;
    }
}