-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate JMX seems not working for application using JPA/Hi
PostPosted: Thu Mar 29, 2007 8:46 am 
Newbie

Joined: Thu Mar 29, 2007 12:52 am
Posts: 6
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>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 6:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
an injected emf, should be castable to (HibernateEntityManagerFactory) then getSessionFactory() should work (not null)

Alternatively
get the session out of a em and do session.getSessionFactory()

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 11:25 am 
Newbie

Joined: Thu Mar 29, 2007 12:52 am
Posts: 6
As I understand

@Resource (PersistenceUnit="...")
EntityManagerFactory emf;

may just be injecting EntityManagerFactory even we specify:

@Resource (PersistenceUnit="...")
HibernateEntityManagerFactory emf;

so emf (javax.persistence.EntityManagerFactory) still don't really implement getSessionFactory() as HibernateEntityManagerFactory does.

Or do I miss something here?

Appreciate your kind elaboration.

Thanks
Max


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 5:53 pm 
Newbie

Joined: Thu Mar 29, 2007 12:52 am
Posts: 6
Hi Emmanuel

Sorry don't quite understand your post (pls see my previous one).

I also tried something like :

HibernateEntityManagerFactory emf = HibernatePersistence.createEntityManagerFactory("SimpleHibernateAppPU",null);

and it didn't work also (as javax.persistence.EntityManagerFactory is supposed to be returnt).

Again, appreciate any advice/elaboration....

Thanks
Max


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.