Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]Hibernate version:[/b]
- Core 3.2.2GA, EntityManager3.3.0GA
[b]Mapping documents:[/b]
- Nil (JPA)
[b]Code between sessionFactory.openSession() and session.close():[/b]
- See below
[b]Full stack trace of any exception that occurs:[/b]
- No exception. Just no JMX stat seen.
[b]Name and version of the database you are using:[/b]
- Derby (can get data from DB)
[b]The generated SQL (show_sql=true):[/b]
[b]Debug level Hibernate log excerpt:[/b]
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
------------------------------------------------------------------------------
Greetings
I'm trying to configure Hibernate JMX on an application using Hibernate Entity Manager, following steps on the Reference Doc Section 2.2 but it does not seem to work (I do not see any JMX statistics (all zeros from Sun JDK JConsole) as compared to successfully seeing JMX statistics for another similar application but using Hibernate Session directly).
My JMX related codes in the Hibernate Entity Manager app include :
MBeanServer mBeanServer = ManagementFactory.getPlatformMB
eanServer();
ObjectName on = new ObjectName("Hibernate:type=statistics,application=SimpleHibernateApp");
StatisticsService statsMBean = new StatisticsService();
statsMBean.setStatisticsEnabled(true);
mBeanServer.registerMBean(statsMBean, on);
I notice for "non-JPA" Hibernate app, the following are needed:
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName on = new ObjectName("Hibernate:type=statistics,application=HibernateTravelPOJO");
StatisticsService statsMBean = new StatisticsService();
statsMBean.setStatisticsEnabled(true);
statsMBean.setSessionFactory(sessionFactory); // setSessionFactory(sf);
mBeanServer.registerMBean(statsMBean, on);
But I do not know how to get sessionFactory in JPA app. I tried something like :
@Resource (PersistenceUnit = "SimpleHibernateAppPU");
HibernateEntityManagerFactory emf;
emf.getSessionFactory(); // getting Null Pointer Exception here
Is somethings similar to
statsMBean.setSessionFactory(sessionFactory);
necessary in application using JPA/Hibernate Entity Manager?
My configuration files are as follow. Appreciate any advice.
Thanks
Max
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="
http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd">
<persistence-unit name="SimpleHibernateAppPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/sample</jta-data-source>
<class>simpleHibernateApp.entities.Manufacturer</class>
<class>simpleHibernateApp.entities.Product</class>
<class>simpleHibernateApp.entities.ProductCode</class>
<properties>
<property name="hibernate.dialect" value=" org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.generate_statistics" value="true" />
<!-- cache configuration -->
<property name=" hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
<property name="hibernate.cache.provider_configuration" value="/ehcache.cfg.xml" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name=" hibernate.ejb.classcache.simpleHibernateApp.entities.Manufacturer" value="read-only"/>
<property name="hibernate.ejb.classcache.simpleHibernateApp.entities.Product" value="read-only"/>
<property name="hibernate.ejb.classcache.simpleHibernateApp.entities.ProductCode" value="read-only"/>
</properties>
</persistence-unit>
</persistence>
ehcache.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<cache name="simpleHibernateApp.entities.Manufacturer "
maxElementsInMemory="300"
eternal="true"
overflowToDisk="false"
/>
<cache name="simpleHibernateApp.entities.Product"
maxElementsInMemory="300"
eternal="true"
overflowToDisk="false"
/>
<cache name="simpleHibernateApp.entities.ProductCode"
maxElementsInMemory="300"
eternal="true"
overflowToDisk="false"
/>
</ehcache>