maxWait="5000"

username="osmsusr"

url="jdbc:oracle:thin:@IP_OR_HOSTNAME_OF_DB_SERVER:1521:osmsdb_ora" maxActive="15"/>

</Context>

Where: IP_OR_HOSTNAME_OF_DB_SERVER is the MySQL or Oracle database server name or IP address.

3.Add the Hibernate3 JAR files to the application library by copying the following files from the Hibernate3 installation directory to $CATALINA_HOME/webapps/SimpleDemo/WEB-INF/lib:

hibernate3.jar dom4j-1.6.1.jar cglig-2.1.3.jar commons-logging-1.0.4.jar commons-collections-2.1.1.jar ehcache-1.1.jar

asm.jar asm-attrs.jar antlr-2.7.6rc1.jar

4.Hibernate uses a configuration file named hibernate.cfg.xml to obtain the database connection information and mapping file information.

Create a Hibernate configuration file named

$CATALINA_HOME/webapps/SimpleDemo/WEB-INF/classes/hibernate.cfg.xml. Add the following lines, depending on whether your database is MySQL or Oracle:

For a MySQL database server:

<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration> <session-factory>

<property name="show_sql">true</property>

<property name="connection.datasource">java:comp/env/MySqlDS</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="com/hp/osms/hibernate/Users.hbm.xml" />

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

For an Oracle database server:

<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC

Installing,Configuring,and Managing Web Application Server Middleware Stack Components 33 "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration>

<session-factory>

<property name="show_sql">true</property>

<property name="connection.datasource">java:comp/env/OracleDS</property> <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> <mapping resource="com/hp/osms/hibernate/Users.hbm.xml" />

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

NOTE: The values of OracleDS and MySqlDS are the data source names that are configured in the Tomcat Web server.

5.In Hibernate, a unit of work is named a session that is managed by SessionFactory.

To retrieve data for a session, create a utility named HibernateSessionFactory.java located in $CATALINA_HOME/webapps/SimpleDemo/WEB-INF/classes/com/hp \

38

Page 38
Image 38
HP 5991-5565 manual Asm.jar asm-attrs.jar antlr-2.7.6rc1.jar