Bug 743662 - Hibernate Statistics plugin does not support JBoss EWS
Hibernate Statistics plugin does not support JBoss EWS
Status: NEW
Product: RHQ Project
Classification: Other
Component: Plugins (Show other bugs)
Unspecified Unspecified
medium Severity unspecified (vote)
: ---
: ---
Assigned To: RHQ Project Maintainer
Mike Foley
: FutureFeature
Depends On:
  Show dependency treegraph
Reported: 2011-10-05 12:38 EDT by Richard Robinson
Modified: 2012-07-17 11:19 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Last Closed:
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Richard Robinson 2011-10-05 12:38:24 EDT
Description of problem:
The hibernate statistics plugin (jopr-hibernate-plugin-3.0.1.GA.jar) does not support Jboss EWS.

Version-Release number of selected component (if applicable):

How reproducible:

jar -xvf jopr-hibernate-plugin-3.0.1.GA.jar
vi rhq-plugin.xml
Inspect the <service> <runs-inside>, which is:

         <parent-resource-type name="JMX Server" plugin="JMX"/>
         <parent-resource-type name="JBossAS Server" plugin="JBossAS"/>
         <parent-resource-type name="JBossAS Server" plugin="JBossAS5"/>

NOTICE there is no <parent-resource-type name="Tomcat Server" plugin="Tomcat"/> in the runs-inside.

Also inspect the rhq-plugin.xml that comes with the EWS plugin (jopr-tomcat-plugin-3.0.1.GA.jar), which plugin has a name of "Tomcat"

Steps to Reproduce:
1. Deploy the jopr-hibernate-plugin-3.0.1.GA.jar to JON 2.4.1 server
2. Update agent (>plugins update)
3. Go into JON GUI and you do not see Hibernate statistics.
4. HOWEVER, assuming you have correctly set up your tomcat in EWS and hibernate statistics in the war -- you can use jconsole and confirm that Hibernate Statistics are indeed working. They just aren't working through the rhq plugin
Actual results:
No Hibernate Statistics for EWS in JON

Expected results:
Hibernate Statistics for EWS in JON

Additional info:
Comment 2 Heiko W. Rupp 2012-07-04 11:12:07 EDT
you say that by adding a line of 

   <parent-resource-type name="TomcatServerComponent" plugin="Tomcat"/>

You got that to run?
Is above the correct type ('TomcatServer' as you wrote in the description seems 
not existent)?

Comment 3 Richard Robinson 2012-07-17 11:19:31 EDT
Hello Heiko,

The above configuration was surmise, based on the pattern seen in the configuration with other parent-resource-type.

It didn't work.

I *did* finally get hibernate statistics to work, however, in Tomcat/Jboss EWS by adding the below included class and calling it in a static method or block in one of the start up classes in our application (war). I believe the code below comes straight out of the docs (somewhere) with minor modifications.

public class HibernateStatistics {

   private static final Logger LOG = Logger.getLogger(HibernateStatistics.class);
   private static final String HIBERNATE_STATISTICS_MBEAN_OBJECTNAME = "Hibernate:application=hibernateStatistics,type=statistics";
   private static boolean enabled = false;

   public static void enableHibernateStatistics(final EntityManager entityManager) {

      if (enabled) {

      try {
         final StatisticsService mBean = new StatisticsService();
         final SessionFactory sessionFactory = getHibernateSession(entityManager).getSessionFactory();
         final ObjectName objectName = new ObjectName(HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
         final MBeanServer jbossMBeanServer = getJBossMBeanServer();
         jbossMBeanServer.registerMBean(mBean, objectName);

         LOG.info("About to enable Hibernate statistics...");
         LOG.info("Hibernate statistics have been enabled.");

      catch (final InstanceAlreadyExistsException iaee) {
         LOG.info("Duplicate MBean registration ignored: " + HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
      catch (final Exception e) {
         LOG.warn("Couldn't register Hibernate statistics MBean.", e);

      enabled = true;

   private static Session getHibernateSession(final EntityManager entityManager) {
      Session session;

      if (entityManager.getDelegate() instanceof EntityManagerImpl) {
         final EntityManagerImpl entityManagerImpl = (EntityManagerImpl) entityManager.getDelegate();
         session = entityManagerImpl.getSession();
      else {
         session = (Session) entityManager.getDelegate();

      return session;

   private static MBeanServer getJBossMBeanServer() {

      final List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
      MBeanServer jbossServer = null;
      for (final MBeanServer server : servers) {
         if ("jboss".equals(server.getDefaultDomain())) {
            jbossServer = server;

      if (jbossServer == null) {
         jbossServer = ManagementFactory.getPlatformMBeanServer();

      return jbossServer;


Note You need to log in before you can comment on or make changes to this bug.