-->
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.  [ 11 posts ] 
Author Message
 Post subject: deploying hibernate application to application server
PostPosted: Mon Jul 17, 2006 2:41 pm 
Newbie

Joined: Thu Jun 22, 2006 3:23 pm
Posts: 12
Hi All,
I have written hibernate application to access stored procedures.How should i deploy this application to Oracle Application server or any appserver.Do i need to create jar file ?Where should i place hibernate-cfg.xml file while deployment.Can anyone give all the necessary steps for deployment.This is urgent , please help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 2:55 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
For a web application you can use following structure

/pages/index.jsp
/pages/login/signin.jsp
/pages/login/signout.jsp
....
/hibernate.cfg.xml
/log4j.properties
/TableOneMapping.hbm.xml
/TableTwoMapping.hbm.xml
/WEB-INF/classes/com/define/mypackage/TableOneMapping.class
/WEB-INF/classes/com/define/mypackage/TableTwoMapping.class


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 4:40 am 
Newbie

Joined: Thu Jun 22, 2006 3:23 pm
Posts: 12
I have to call these hibernate DAOs from session bean.How should i write my session bean to invoke hibernate code.How should my project structure look.Can anyone provide deatail steps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 5:30 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
something like:

1. put the hibernate.cfg at the top of your java src tree

1. configure hibernate including these properties

Code:
<session-factory name="java:/comp/env/hibernate/SessionFactory">

<property name="transaction.manager_lookup_class">
  org.hibernate.transaction.OrionTransactionManagerLookup
</property>
       
<property name="hibernate.transaction.factory_class">
  org.hibernate.transaction.CMTTransactionFactory
</property>
       
<property name="hibernate.transaction.auto_close_session">
  true
</property>
       
<property name="hibernate.dialect">
  org.hibernate.dialect.Oracle9Dialect
</property>

<property name="hibernate.connection.datasource">
  java:comp/env/jdbc/myDS
</property>


2. write a startup servlet to read the hibernate config (from your classpath) the session factory store in JNDI

3. In your stateless session ejb (CMT/Required) lookup the session factory in JNDI and start using hibernate API

Your EJB/DAO code will be in your application-ejb.jar and hibernate libraries in your ear file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 5:29 pm 
Newbie

Joined: Thu Jun 22, 2006 3:23 pm
Posts: 12
Hi,
Thanks for your reply.Can you please send sample code to access hibernate DAO from session bean.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 9:06 pm 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
your session ejb code:

Code:
MyDAO dao = new MyHibernateDAO();
return dao.findSomething(id);


your dao code:

Code:
Session session = this.getCurrentSession()
return (MyClass) session.load(MyClass.class, id);


your DAO constructor might contain something like:

Code:
String jndiLoc = "java:/comp/env...SessionFactory";
this.mSessionFactiory = (SessionFactory) serviceLocator.lookup(jndiLoc);


your getCurrentSession() might do something like:

Code:
if( ! this.mSessionFactory.isClosed()) {
  return mSessionFactory.getCurrentSession();
} else {
  throw new MyHibernateConfigException("session factory closed");
}



Hope this helps


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 1:02 am 
Newbie

Joined: Thu Jun 22, 2006 3:23 pm
Posts: 12
Thanks for your reply.I will try it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 11:29 am 
Newbie

Joined: Thu Jun 22, 2006 3:23 pm
Posts: 12
Hi,
I tried accessing DAO from sessionbean as per your example code.I am getting following error when deploying my ear file to appserver

[19-Jul-2006 16:07:50] Application Deployer for TestEjbHibernate STARTS.
[19-Jul-2006 16:07:50] Copy the archive to C:\product\10.1.3\OracleAS_1\j2ee\home\applications\TestEjbHibernate.ear
[19-Jul-2006 16:07:50] Initialize C:\product\10.1.3\OracleAS_1\j2ee\home\applications\TestEjbHibernate.ear begins...
[19-Jul-2006 16:07:50] Unpacking TestEjbHibernate.ear
[19-Jul-2006 16:07:50] Done unpacking TestEjbHibernate.ear
[19-Jul-2006 16:07:50] Unpacking cai-web.war
[19-Jul-2006 16:07:51] Done unpacking cai-web.war
[19-Jul-2006 16:07:51] Initialize C:\product\10.1.3\OracleAS_1\j2ee\home\applications\TestEjbHibernate.ear ends...
[19-Jul-2006 16:07:51] Starting application : TestEjbHibernate
[19-Jul-2006 16:07:51] Initializing ClassLoader(s)
[19-Jul-2006 16:07:51] Initializing EJB container
[19-Jul-2006 16:07:51] Loading connector(s)
[19-Jul-2006 16:07:51] Starting up resource adapters
[19-Jul-2006 16:07:51] Processing EJB module: cai-ejb.jar
[19-Jul-2006 16:07:51] Operation failed with error: com/cai/datamatching/model/LookupList

I placed my jsps,DAO(in web-inf/classes) in war file and ejbs in jar file.Altogether i packed as ear file and deployed.If this is not proper way to package please suggest me how i should do.I don't want to package DAO with ejbs because DAOs should be accessible to other layers also.So please suggest me on this.Do i need to specify any mapping in ejb-jar.xml regarding DAO location.Please provide detail steps


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 8:37 pm 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
Soumya wrote:
Hi,
I tried accessing DAO from sessionbean as per your example code.I am getting following error when deploying my ear file to appserver

[19-Jul-2006 16:07:50] Application Deployer for TestEjbHibernate STARTS.
[19-Jul-2006 16:07:50] Copy the archive to C:\product\10.1.3\OracleAS_1\j2ee\home\applications\TestEjbHibernate.ear
[19-Jul-2006 16:07:50] Initialize C:\product\10.1.3\OracleAS_1\j2ee\home\applications\TestEjbHibernate.ear begins...
[19-Jul-2006 16:07:50] Unpacking TestEjbHibernate.ear
[19-Jul-2006 16:07:50] Done unpacking TestEjbHibernate.ear
[19-Jul-2006 16:07:50] Unpacking cai-web.war
[19-Jul-2006 16:07:51] Done unpacking cai-web.war
[19-Jul-2006 16:07:51] Initialize C:\product\10.1.3\OracleAS_1\j2ee\home\applications\TestEjbHibernate.ear ends...
[19-Jul-2006 16:07:51] Starting application : TestEjbHibernate
[19-Jul-2006 16:07:51] Initializing ClassLoader(s)
[19-Jul-2006 16:07:51] Initializing EJB container
[19-Jul-2006 16:07:51] Loading connector(s)
[19-Jul-2006 16:07:51] Starting up resource adapters
[19-Jul-2006 16:07:51] Processing EJB module: cai-ejb.jar
[19-Jul-2006 16:07:51] Operation failed with error: com/cai/datamatching/model/LookupList

I placed my jsps,DAO(in web-inf/classes) in war file and ejbs in jar file.Altogether i packed as ear file and deployed.If this is not proper way to package please suggest me how i should do.I don't want to package DAO with ejbs because DAOs should be accessible to other layers also.So please suggest me on this.Do i need to specify any mapping in ejb-jar.xml regarding DAO location.Please provide detail steps


Does the class "com/cai/datamatching/model/LookupList" exist in your cai-ejb.jar file? Files/libraries in your cai-web.war are not visible to ejb container.

Where do you normally place classes required by your EJB's / deployed J2EE applications? Are the DAO's being used by your web container or by your ejb container? Your persistant classes are probably required in both your cai-web.war and cai-ejb.jar file.

I suppose you could package your DAO (and dependants) into a jar in your ear file (your cai-ejb.jar manifest.mf should have a classpath entry which includes necessary jars). Jars in the ear should be accessible in both web/ejb tiers.

e.g.

Code:
Manifest-Version: 1.0
Class-Path: log4j-1.2.11.jar commons-logging-1.0.4.jar hibernate-3.1.3
.jar ehcache-1.1.jar asm-1.5.3.jar asm-attrs-1.5.3.jar dom4j-1.6.1.ja
r antlr-2.7.6rc1.jar cglib-2.1.3.jar commons-collections-3.1.jar


I'm not sure that this is really a hibernate problem, as the error does not indicate any hibernate messages.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 3:07 am 
Newbie

Joined: Thu Jun 22, 2006 3:23 pm
Posts: 12
Hi,
First of all i would like to thank for your immediate replies.
"com/datamatching/model/LookupList" doesn't exist in my cai-ejb.jar .I placed hibernate DAO and test jsp in cai-web.war.Problem is not with hibernate because i am getting ClasssNotFound Exception .Moreover i tested hibernate DAO deploying to appserver as a war file and accessed it from jsp it is working fine.My DAOs should be available to session beans(ejb container) and also other layers so i should not package my DAO with sessionbean.As per your suggestion i will try placing DAO in jar file and specifying classpath in Manifest.I will let you know if it works properly.
Thank you very much for your suggestion.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 6:52 am 
Newbie

Joined: Thu Jun 22, 2006 3:23 pm
Posts: 12
Hi,
I have deployed ear to appserver editing MANIFEST.MF as per your suggestion.It is working fine.Thank You Very Much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.