-->
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.  [ 10 posts ] 
Author Message
 Post subject: Cookbook for running Hibernate in IBM WSAD 5.x
PostPosted: Thu Feb 12, 2004 12:52 am 
Newbie

Joined: Fri Jan 30, 2004 12:56 am
Posts: 5
Location: Salt Lake City
This document outlines the steps for running Hibernate with an EJB application in the WSAD 5.x environment, using the
hibernate.cfg.xml flavor for the Configuration. This example assumes an Oracle9 database, but any flavor can, off course, be substituted.

The set-up of the DataSource in step 7 and 8 refers to settings for the Server configuration (test server) within WSAD.

1. Create the EAR and EJB applications as you normally do.

2. Add the folowing jar archives to the EAR by importing them from the file system:
cglib2.jar
commons-collections.jar
commons-logging.jar
dom4j.jar
hibernate2.jar
odmg.jar
xalan.jar

3. Add the above jars to the project's java build path

4. Place the jar file commons-lang.jar in the server's ext library (Don't know why this is, but it's
the only way it will work. Maybee a subsequent version of hibernate will fix this).

5. Add commons-lang.jar to the project's java build path.

6. The supporting files for hibernate are now in place.

7. Configure a DataSource the normal way. (I also set up a JAASC Authentication entry under the Security tab and then set the Container managed Authentication Alias for the DataSource to that )

8. Create a resource reference to the DataSource from the EJB Deployment descriptor:
name: jdbc/data_source_name
type: javax.sql.DataSource
authentication: Container
Sharing Scope: Shareable
jndi name: jdbc/data_source_name
Isolation level: TRANSACTION_READ_COMMITTED
Connection Policy: Default

8. Create the class.hbm.xml files and hibernate.cfg.xml and place them at the EJB module level.

9. An example hibernate.cfg.xml that makes use of the DataSource set up in step 7:

Code:
<?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE hibernate-configuration
   PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
    <hibernate-configuration>
      <session-factory>
   
      <!-- Data Source -->
      <property name="connection.datasource">java:comp/env/jdbc/data_source_name</property>

      <!-- Database Settings -->
      <property name="default_schema">SCHEMA_NAME</property>
      <property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>
      <property name="show_sql">true</property>
      
      <!-- JDBC Settings -->
      <property name="jdbc.use_streams_for_binary">true</property>
      <property name="max_fetch_depth">1</property>
      
      <!-- Cache settings -->
      <property name="cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property>
      <!-- Transaction API -->
      <property name="transaction.manager_lookup_class">
         net.sf.hibernate.transaction.WebSphereTransactionManagerLookup</property>
         
      <!-- Mapping files -->
      <mapping resource="Event.hbm.xml"/>
      <mapping resource="Attendance.hbm.xml"/>
      <mapping resource="Offering.hbm.xml"/>
      <mapping resource="OfferingAssistance.hbm.xml"/>
      <mapping resource="OfferingStatusCode.hbm.xml"/>
      <mapping resource="Site.hbm.xml"/>
      <mapping resource="SubjectArea.hbm.xml"/>

    </session-factory>
   </hibernate-configuration>


You should now be able to code a simple client inside a SessionBean that accesses your data. My (rough) code goes something like this:
Code:
SessionFactory sessions = null;
      try {
         sessions = new Configuration().configure().buildSessionFactory();
         //sessions = cfg.buildSessionFactory();

      } catch (HibernateException e) {
         print(" Exception creating sessionfactory: " + e.getMessage());
      }
      Session session = null;
      try {
         session = sessions.openSession();
BigDecimal num = new BigDecimal("12");
SubjectArea holder = (SubjectArea) session.load(SubjectArea.class, num);
         System.out.println("-->Loaded SubjectArea object (PARENT) ");
         System.out.println("------------------------------");
         System.out.println("-->subjectAreaID = " + holder.getSbjAreaName());
         System.out.println("-->Subject area void indicator = " + holder.getSbjAreaVoidInd());
         System.out.println("-->Got " + holder.getEvents().size() + " Event objects");
         System.out.println("-------------------------------\n");

.........
.........
Hope this helps those of you out there new to Hibernate in the WSAD environment. Please add to this. (I'll try to add the deployment part onto WAS once I understand it.)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 7:04 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Cool ! please add it to the wiki area.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 11:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I have added this to the WIKI at http://www.hibernate.org/173.html. Thanks for the explanations.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 8:09 am 
Newbie

Joined: Mon Jan 12, 2004 6:23 am
Posts: 5
I got Hibernate working in WSAD 5.1 without having to put commons-lang.jar in the ext classpath - this was from a web application though.

What problems do you get? I don't think it should be necessary to have the same jar twice in the classpath.


Peter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate core no longer depends upon commons-lang.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 9:28 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Hi,

I think some of your instructions might change depending on classloader "mode" in was5x. It is my understanding that was5x defaults to "parent_first" classloader- meaning if it comes with was runtime- IBM's versions of stuff will load before your own. Can you tell us /indicate on wikki how you have classloader for the application configured?

WAS 5 comes with struts, commons logging in it's own runtime. In most cases we use "PARENT_LAST" classloading. This requires the creation of a file "commons-logging.properties" at the root of the app source code to keep WAS from loading it's own packaged version of logger.

--James


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 2:11 pm 
Newbie

Joined: Tue Feb 03, 2004 11:58 am
Posts: 11
Step #7:
"Configure a DataSource the normal way. (You may need to set up a JAASC Authentication entry on the Security tab of the server configuration, and then set the Container managed Authentication Alias for the DataSource to that entry)"

Question:
In setting a DataSource: in the "JDBC provider list:" I suppose I should select "Default DB2 JDBC Provider" with "COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource" for the "Implementation class name" if dealing with DB2 database.
If that is correct, which version of the Data Source did you select in the
"Data source defined in the JDBC provider selected above:": version 4 or 5.

Step #8:
"Create a resource reference for the SLSB refering to the DataSource (EJB Deployment descriptor):


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 8:47 pm 
Newbie

Joined: Mon Jul 19, 2004 8:42 pm
Posts: 2
Does anybody can tell me where is the "server's ext library"? Sorry for this silly question and I'm wating online.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 5:55 am 
Newbie

Joined: Mon Jul 19, 2004 8:42 pm
Posts: 2
I have got it work.
My enviroment is WSAD IE 5.1, I use a SessionBean to invoke hibernate. step4 is not necessary.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 9:17 pm 
Newbie

Joined: Wed Nov 02, 2005 5:33 am
Posts: 12
Did you deploy your Hibernate Application onto WAS v5.1.2? If yes, could you please tell me how ? i has been stuck on this point for a week and the deadline for my project will come soon!

Regards,
--------------------------
thanh.hoc@gmail.com
--------------------------


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