-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How do i configure hibernate with JBoss
PostPosted: Tue Mar 13, 2007 10:04 am 
Newbie

Joined: Tue Mar 13, 2007 9:53 am
Posts: 6
Location: HCL Technologies Ltd,N.M Road ,Chennai-600029,NungumBakam,India.

Hi ,I'm new to hibernate with three tier.I have experience on usage of hibernate with two-tier.Can any one helps me to configure hibernate with JBoss.We are migrating our application from JDBC to hibernate.

_________________
Cheers,
Naga Nirangen , R.


Top
 Profile  
 
 Post subject: Migrate hibernate with jboss
PostPosted: Wed Mar 14, 2007 1:15 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 7:52 am
Posts: 20
hi

first u create the JNDI in JBoss Application server
first configure the the mysql-ds.xml file
jboss-4.0.4.GA\docs\examples\jca\mysql-ds.xml
copy that file into
C:\Program Files\jboss-4.0.4.GA\server\default\deploy

and configure the database driver ,url and JNDI name ...........etc
and you must configure hibernate-cfg.xml file like this


<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">

<!-- datasource connection properties -->
<property name="connection.datasource">java:comp/env/MySqlDS</property>
<!-- dialect for MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->

</hibernate-configuration>

this is hibernate with jndi on jboss server configuration

this is helped to you plez give the Crdit(dont forgot)


Top
 Profile  
 
 Post subject: hibernate with jboss
PostPosted: Wed Mar 14, 2007 2:42 am 
Newbie

Joined: Wed Mar 07, 2007 3:26 am
Posts: 16
Location: Hyderabad,India
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.

_________________
sam


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.