hi, narender
follow these steps...
Steps to deploy a Hibernate 1.X or 2.0 service in JBoss
1. Prepare your JDBC DataSource for use with Hibernate.
Please refer to JBoss docs, or the examples included in the JBoss distribution.
2. Copy the necessary jars to ${JBOSS_HOME}/server/default/lib.
The following jars are required (maybe redundant?), which can be found in ${HIBERNATE_HOME}/lib:
cglib.jar
commons-collections.jar
commons-logging.jar
commons-lang.jar
jcs.jar
odmg.jar
and of course, hiberna
Due to some mysterious ClassLoader problems in JBoss, these jars have to be copied to ${JBOSS_HOME}/server/default/lib. And in addition, you may need to use the latest versions of the commons-*.jar if JBoss failed to start up after copying (the commons-*.jar in Hibernate's distribution seems to cause conflict with JBoss itself... maybe it means not all the commons-*.jar are necessary? :\).
3. Prepare the directory structure of the service archive.
The Hibernate service will be deployed as a service archive (SAR), which will include all the entity objects, mapping XML files, and the JBoss service XML file itself.
Prepare a directory structure like this:
org/mytest/objects/MasterAccount.class
org/mytest/objects/SubAccount.class
org/mytest/objects/Password.class
mappings/MasterAccount.hbm.xml
mappings/SubAccount.hbm.xml
mappings/Password.hbm.xml
META-INF/
4. Prepare the service XML file.
Fire up your favorite text editor and type in the Hibernate service MBean configuration, like the one below:
<server>
<mbean code="cirrus.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<!-- Make it deploy ONLY after D.hbm.xml, XXX SOMETHING IS MISSING HERE, PLEASE FIX !! XXX
mappings/SubAccount.hbm.xml,
mappings/Password.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/jdbc/DataSource</attribute>
<attribute name="Dialect">cirrus.hibernate.sql.MySQLDialect</attribute>
<attribute name="TransactionStrategy">cirrus.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">
cirrus.hibernate.transaction.JBossTransactionManagerLookup
</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">java:/UserTransaction</attribute>
</mbean>
</server>
The following classpaths will work with hibernate 2.x
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">mappings/Attribute.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/MySqlDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>
Of course, you will want to change the attributes above.
MapResources: a list of the mapping files used, separated by commas.
JndiName: the JNDI bound name of the Hibernate service.
Datasource: the JDBC data source this Hibernate service will use.
Dialect: the SQL dialect the Hibernate service will use. please refer to
http://hibernate.bluemars.net/hib_docs/ ... ation.html to see the list of available dialects.
UseOuterJoin: whether Hibernate should use outer join fetching.
ShowSql: prints out the SQL (actually a PreparedStatement) generated by Hibernate when set to true.
Save this file as jboss-service.xml and put it under META-INF of your directory structure.
5. Pack the directory up as a JAR with .sar as extension.
Issue a jar command to jar the above contents to a service archive, which ends with .sar. It is not required to use sar as its extension, just for some sort of conformance... :)
You may also want to do this job with an Ant target.
6. Copy the archive to ${JBOSS_HOME}/server/default/deploy.
You will then see the Hibernate service initialized. You may need to check with your mappings and/or jboss-service.xml in case any exception is thrown.