This content has been marked as final.
Show 2 replies
-
1. Re: Hibernate StatisticsService MBean doesnt work with Entit
jaikiran May 15, 2008 3:37 AM (in response to adlepoo)The EntityManager has a getDelegate API: http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html#getDelegate()
You can probably do this:@PersistenceContext EntityManager em; public void myMethod() { //get the underlying Hibernate session org.hibernate.Session sess = (org.hibernate.Session) em.getDelegate(); //now get the session factory from the hibernate session SessionFactory sf = sess.getSessionFactory(); }
P.S: I don't know why JPA doesn't provide a similar getDelegate() method on the EntityManagerFactory to access the provider specific entitymanagerfactory. -
2. Re: Hibernate StatisticsService MBean doesnt work with Entit
adlepoo May 15, 2008 9:40 AM (in response to adlepoo)Thanks! I like your solution better than the one I was testing.
I set the hibernate.session_factory_name property and did a JNDI lookup to get the SessionFactory.
It seems to work, but I like getting the SessionFactory directly from the EntityManager (via EMFactory) instead of a backdoor method.
Regards,