Announcement Announcement Module
Collapse
No announcement yet.
Lazy-Initialized MBeans & org.hibernate.jmx.HibernateSer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lazy-Initialized MBeans & org.hibernate.jmx.HibernateSer

    Hi all, i am using the JBoss 3.2.7, Hibernate 3.0.5 and Spring Framework 1.2.4.
    My intention is register the Hibernate like an MBean using the spring.
    This approach will provide a SessionFactory that i can access Using JNDI and inject in my DAO´s classes.
    The MBean registration works fine, however the MBeanExporter doesn´t instantiate (call the start() method) the bean. I presume that it happens because MBeanExporter is configured for lazy initialization. There is some way change this behavior ?

    My application-context.xml is something like that:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <bean id="jmxAdapter" class="org.springframework.jmx.export.MBeanExporte r">
    <property name="beans">
    <map>
    <entry key="curso:service=HibernateService">
    <ref local="HibernateService"/>
    </entry>
    </map>
    </property>
    </bean>
    <bean id="HibernateService" class="org.hibernate.jmx.HibernateService">
    <property name="mapResources">
    <value>
    model/Category.hbm.xml,
    model/Account.hbm.xml
    </value>
    </property>
    <property name="datasource" value="java:/DBCURSO"/>
    <property ame="dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
    <property name="jndiName" value="java:/HibernateFactory_CUR"/>
    </bean>

    <bean id="cursoSessionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="java:/HibernateFactory_CUR"/>
    </bean>


    here i receive an exception because my MBean doesn´t instantiated and i don´t have the session factory registered in JNDI

  • #2
    Force eager initialization using the lazy-init attribute.

    Comment


    • #3
      Originally posted by costin
      Force eager initialization using the lazy-init attribute.
      Costin i put the lazy-init="false" attribute in my bean (HibernateService) but the MBeanExporter doesn´t call the bean´s start method.
      Somebody knows why ?

      My application-context.xml seems like that:

      <bean id="jmxAdapter" class="org.springframework.jmx.export.MBeanExporte r">
      <property name="beans">
      <map>
      <entry key="curso:service=HibernateService">
      <ref local="HibernateService"/>
      </entry>
      </map>
      </property>
      </bean>
      <bean id="HibernateService" lazy-init="false" class="org.hibernate.jmx.HibernateService">
      <property name="mapResources">
      <value>
      model/Category.hbm.xml,
      model/Account.hbm.xml
      </value>
      </property>
      <property name="datasource" value="java:/DBCURSO"/>
      <property name="dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
      <property name="jndiName" value="java:/HibernateFactory_CUR"/>
      </bean>

      Comment


      • #4
        Use also init-method when you declare your HibernateMBean (init-method="start").

        Comment


        • #5
          Originally posted by costin
          Use also init-method when you declare your HibernateMBean (init-method="start").
          Thanks Costin, it works fine

          Comment

          Working...
          X