Announcement Announcement Module
No announcement yet.
Configuring org.hibernate.jmx.HibernateService MBean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring org.hibernate.jmx.HibernateService MBean

    I am trying to configured the HibernateService message bean using
    an existent session factory, so that it can be managed remotetly.
    however, there is not sessionFactory property to set, like there is in
    the other Hibernate message bean, StatisticsService. From reading
    the javadocs for HibernateService, it seems like this class creates
    its own Session Factory, but it does not exposed it, I will like to
    keep using the session factory I have created with LocalSessionFactoryBean.

    Here is a the relevant Spring configuration:

    <!-- Hibernate Session Factory -->

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean" lazy-init="false">
    <property name="dataSource">
    <ref local="dataSource"/>
    <property name="mappingJarLocations">
    <property name="hibernateProperties">
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.max_fetch_depth">${hibernate.max_fe tch_depth}</prop>

    <!-- ************** Hibernate JMX Beans **************** -->

    <bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
    <property name="statisticsEnabled">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>



  • #2
    Take a look at the sources and see what the service is doing - I think it firsts looks a session factory through JNDI and in case it doesn't find one it create one.


    • #3
      I will take a look at the sources. The docs make it sound

      as if the JNDI name passed is used to bind a Session Factory, that is created, the HibernateService

      ---> From the javadocs

      public void setJndiName(String jndiName)Description copied from interface: HibernateServiceMBean
      The JNDI name to bind to the SessionFactory

      Specified by:
      setJndiName in interface HibernateServiceMBean
      jndiName -

      Now, I will hope that you are correct that the JNDI passed, it is
      used to de-reference an existent SessionFactory, that way, I can
      just register my existent one with a Spring JNDI Exporter class. However,
      if it is not, I will not be able to use the HibernateService MBean, as
      I really prefer to configure the SessionFactory myself with a DataSource of my choice, and the HibernateService class does not give that option.

      Thanks for your help. I will download the Hibernate source code in the next few days and take a look.



      • #4
        HibernateService class creates its own SessionFactory

        Well, the setJndiName() method in HibernateService, it is to bind
        a name to the SessionFactory that HibernateService creates, there is not option to pass this in, the top comment in the class also makes
        this clear.

        * Implementation of <tt>HibernateServiceMBean</tt>. Creates a
        * <tt>SessionFactory</tt> and binds it to the specified JNDI name.<br>
        * <br>
        * All mapping documents are loaded as resources by the MBean.
        * @see HibernateServiceMBean
        * @see org.hibernate.SessionFactory
        * @author John Urberg, Gavin King
        public class HibernateService extends ExternalSessionFactoryConfig implements HibernateServiceMBean {

        Furthermore, the builSessionFactory method in the class is not made

        I guess for now I can not use an external configurable DataSource
        and use the HibernateService MBean, wonder why ?

        Perhaps there is something I missed, if anybody sees a way
        around this, let me know.

        My goal is to use the Apache Data Source to create a SessionFactory
        and then create a HibernateService MBean that uses that factory, just
        like the StatisticsService has a sessionFactory() method.



        • #5
          Right. You can check the HB forums for more info but I think the initial purpose of the HibernateService was to create the session and publish it to JNDI. I guess you can just simply create your own SessionFactory and then put a JMX wrapper around as the service is not that reusable, at least IMO.


          • #6
            Hibernate stats bean

            I did manage to get it running in Tomcat (w/Spring) with the following code:

            <bean id="registry"
            class="org.springframework.remoting.rmi.RmiRegistr yFactoryBean">
            <property name="port" value="1099" />

            <bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
            <property name="sessionFactory" ref="sessionFactory" />

            <bean id="exporter" class="org.springframework.jmx.export.MBeanExporte r">
            <property name="beans">
            <entry key="bean:name=statistics" value-ref="statisticsBean" />

            <bean id="clientConnector"
            class=" rverFactoryBean">
            <property name="objectName" value="connector:name=rmi" />
            <property name="serviceUrl"
            value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector" />