Results 1 to 6 of 6

Thread: Configuring org.hibernate.jmx.HibernateService MBean

  1. #1
    Join Date
    Aug 2005
    Location
    Newport Beach, California
    Posts
    3

    Default 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Aug 2005
    Location
    Newport Beach, California
    Posts
    3

    Default 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

  4. #4
    Join Date
    Aug 2005
    Location
    Newport Beach, California
    Posts
    3

    Default 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

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6

    Default 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>

Similar Threads

  1. JBoss MBean Deployment
    By redijedi in forum Management
    Replies: 4
    Last Post: Feb 22nd, 2012, 04:09 AM
  2. Replies: 6
    Last Post: Apr 28th, 2010, 07:57 AM
  3. Exposing Remote Objects as MBean
    By Anonymous in forum Management
    Replies: 0
    Last Post: Sep 23rd, 2005, 05:42 PM
  4. Configuring the validator
    By anieshuk in forum Web
    Replies: 2
    Last Post: Aug 1st, 2005, 04:12 AM
  5. Replies: 1
    Last Post: Nov 26th, 2004, 06:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •