Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 73089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:08:48+00:00 2026-05-10T20:08:48+00:00

I’ve set hibernate.generate_statistics=true and now need to register the mbeans so I can see

  • 0

I’ve set hibernate.generate_statistics=true and now need to register the mbeans so I can see the statistics in the jmx console. I can’t seem to get anywhere and this doesn’t seem like it should be such a difficult problem. Maybe I’m making things overcomplicated, but in any case so far I’ve tried:

  • I copied EhCacheProvider and had it instantiate an extended version of CacheManager which overloaded init() and called ManagementService.registerMBeans(…) after initialization. The code all ran fine until the actual call to registerMBeans(…) which would cause the provider initialization to fail with a generic error (unfortunately I didn’t write it down.) This approach was motivated by the methods used in this liferay performance walkthrough.
  • I created my own MBean with a start method that ran similar code to this example of registering ehcache’s jmx mbeans. Everything appeared to work correctly and my mbean shows up in the jmx console but nothing for net.sf.ehcache.
  • I’ve since upgraded ehcache to 1.5 (we were using 1.3, not sure if that’s specific to jboss 4.2.1 or just something we chose ourselves) and changed to using the SingletonEhCacheProvider and trying to just manually grab the statistics instead of dealing with the mbean registration. It hasn’t really gone any better though; if I call getInstance() the CacheManager that’s returned only has a copy of StandardQueryCache, but jboss logs show that many other caches have been initialized (one for each of the cached entities in our application.)

EDIT: Well I have figured out one thing…connecting via JConsole does reveal the statistics mbeans. I guess ManagementFactory.getPlatformMBeanServer() doesn’t give you the same mbean server as jboss is using. Anyway it looks like I’m encountering a similar problem as when I tried collecting the statistics manually, because I’m getting all zeros even after clicking through my app for a bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:08:49+00:00Added an answer on May 10, 2026 at 8:08 pm

    Solved. Since I was not seeing all the caches for my entities I suspected I was not getting the right SessionFactory instance. I started out with this line (see the example jmx registration code in the link I provided in the question):

    SessionFactory sf = (new Configuration()).configure().buildSessionFactory(); 

    The end result was the cache manager I ultimately ended up with was a new instance and not the one from the persistence context. So I tried refactoring as:

    EntityManagerFactory emf = Persistence.createEntityManagerFactory('myPersistenceUnit'); return ((EntityManagerFactoryImpl)emf).getSessionFactory(); 

    but that just threw an exception (I don’t remember the exact text; something to the effect of ‘can’t initialize persistence context.’) So left with no other options, I added a stateless bean (UtilMgr) to my application and let persistence inject the correct SessionFactory. Here’s that bean:

    import javax.ejb.Stateless; import javax.persistence.PersistenceUnit; import net.sf.ehcache.CacheManager; import org.hibernate.SessionFactory;  @Stateless public class UtilMgrBean implements UtilMgr {     // NOTE: rename as necessary     @PersistenceUnit(unitName = 'myPersistenceCtx')     private SessionFactory sessionFactory;      public SessionFactory getSessionFactory() {         return this.sessionFactory;     }      public CacheManager getCacheManager() {         return CacheManager.getInstance(); // NOTE: assumes SingletonEhCacheProvider     } } 

    and here’s the corrected code from the previously mentioned walkthrough:

    try {     // NOTE: lookupBean is a utility method in our app we use for jndi lookups.     //   replace as necessary for your application.     UtilMgr utilMgr = (UtilMgr)Manager.lookupBean('UtilMgrBean', UtilMgr.class);     SessionFactory sf = utilMgr.getSessionFactory();     MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();      // NOTE: replace myAppName as necessary     ObjectName on = new ObjectName('Hibernate:type=statistics,application=myAppName');      // Enable Hibernate JMX Statistics     StatisticsService statsMBean = new StatisticsService();     statsMBean.setSessionFactory(sf);     statsMBean.setStatisticsEnabled(true);     mbs.registerMBean(statsMBean, on);      CacheManager cacheMgr = utilMgr.getCacheManager();     ManagementService.registerMBeans(cacheMgr, mbs, true, true, true, true); } catch(Throwable t) {     throw new RuntimeException(t); } 

    You can also use this getCacheManager() method of UtilMgr if you want to retrieve statistics manually (which is what I’ll probably do anyway.) You can find more info about how use use the Cache and Statistics objects in the ehcache code samples.

    If anyone can fill me in on a way to statically lookup the session factory without the need for creating this extra session bean, I’d love to hear it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Regardless of which database you are using, it can be… May 11, 2026 at 2:25 pm
  • added an answer Nathan W has already suggested the IntPtr structure which can… May 11, 2026 at 2:25 pm
  • added an answer You could do a simple copy and paste (i.e. copy… May 11, 2026 at 2:25 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.