Adding ShowSql as an attribute for the HibernateServiceMBean. Patch is posted on the sourceforge site.

I am unable to do a diff on the jmx.html page do to the error I got "\ No newline at end of file". Something to do with \n and \r!!! I have attached the jmx.html file with the updates.

Hibernate JMX in JBoss


This document assumes you have properly configured JBoss for you environment including any data sources you will require. Assistance in doing so can be found at

http://www.jboss.org

This document was based upon JBoss 3.0.0 and Hibernate 1.1 beta 7. The first step to installing Hibernate in JBoss via JMX is to create the hibernate-service.xml. An example file is below:


<?xml version="1.0" encoding="UTF-8"?>

<service>

        <mbean code="cirrus.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">

                <classpath codebase=""

                        lib="C:\java\jboss-3.0.0\server\default\deploy\persistent-classes.jar"/>

                <depends>jboss.jca:service=RARDeployer</depends>

                <attribute name="MapResources">Counter.hbm.xml, CounterInstance.hbm.xml, Measurement.hbm.xml, MonitoringObject.hbm.xml, Server.hbm.xml</attribute>

                <attribute name="JndiName">java:/HibernateFactory</attribute>

                <attribute name="Datasource">java:/MSSQLDS</attribute>

                <attribute name="Dialect">cirrus.hibernate.sql.SybaseDialect</attribute>

                <attribute name="ShowSql">false</attribute>

        </mbean>

</service>

I found that I had to supply a codebase and lib via the <classpath> element. This may not be required in all cases. persistent-classes.jar contained all of my Hibernate persistent classes and *.hbm.xml mapping documents. The following MBean attributes were needed

  • MapResources contains a comma separated list of your mapping files
  • JndiName specifes the JNDI name of the Hibernate SessionFactory
  • Datasource specifies the JNDI name of the datasource you wish to use with Hibernate (this must have been created prior to deployment of this file)
  • Dialect specifies the Hibernate SQL Dialect
  • ShowSql specifies if SQL statements should be printed to the console ShowSql

The following attributes are also supported

  • UserName the database user
  • Password the database password
  • UseOuterJoin (dis)enable outerjoin fetching (the default setting for the Dialect should be fine)
  • TransactionStrategy the name of a Hibernate TransactionFactory subclass if you wish to use the Transaction API
  • UserTransactionName for JBoss this should be java:comp/UserTransaction, which is the default

Now that you have a service file, copy persistent-classes.jar and hibernate-service.xml to the appropriate deploy directory. In this example it is the default server found at C:\java\jboss-3.0.0\server\default\deploy. It is important to copy the hibernate-service.xml last as it depends upon the jar being there first.

Check the JBoss standard output (command window) to make sure there were no errors. A successful deployment will look something like:


10:16:29,563 INFO  [MainDeployer] Starting deployment of package: file:/C:/java/jboss-3.0.0/server/default/deploy/hibernate-service.xml

followed by several lines of Hibernate log messages ending with


10:16:38,997 INFO  [MainDeployer] Successfully completed deployment of package: file:/C:/java/jboss-3.0.0/server/default/deploy/hibernate-service.xml

Any errors will likely be in the form of stack traces between those two lines. If you do encounter an error, delete the hibernate-service.xml which will undeploy the JMX service automatically. From there, you can make any changes to your deployment and try again.

After you have successfully deployed the service, you will have a SessionFactory bound to the specified JNDI name. In our example it is at java:/HibernateFactory.To access from an EJB or web application, simply acquire a Context and look it up like any other JNDI resource:


Context ctx = new InitialContext();

SessionFactory factory = (SessionFactory) ctx.lookup("java:/HibernateFactory");

If you leave the hibernate-service.xml in the appropriate deploy directory, it will automatically be undeployed at server shutdown and deployed at startup. You can start or stop the service or make changes to the attributes (such as adding a mapping) via the JBoss JMX management console. The console is generally found on port 8082.

- Jon White


This document was generated using AFT v5.0793

Reply via email to