Announcement Announcement Module
Collapse
No announcement yet.
Configuring org.hibernate.jmx.HibernateService MBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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>
    <property name="mappingJarLocations">
    <value>dbmaps.jar</value>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.max_fetch_depth">${hibernate.max_fe tch_depth}</prop>
    </props>
    </property>
    </bean>


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

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


    thanks

    Gustavo

  • #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.

    Comment


    • #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
      Parameters:
      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.

      Gustavo

      Comment


      • #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
        public.

        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.

        Gustavo

        Comment


        • #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.

          Comment


          • #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>


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

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

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

            Comment

            Working...
            X