org.hibernate.Session hbsession = HibernateSessionFactory.getSession(); try{

Transaction tx = hbsession.beginTransaction(); Users users= new Users();

users.setFirstName("Smith");

users.setLastName("Barney");

hbsession.save(users);

hbsession.flush();

tx.commit();

}catch(HibernateException he){ he.printStackTrace();

}finally

{

if(hbsession!=null)

HibernateSessionFactory.closeSession();

}

NOTE: See “Appendix D: Hibernate Test Application Source Code” (page 55) for the complete source code.

11.Restart Tomcat to make the configuration effective by entering the following:

#$CATALINA_HOME/bin/shutdown.sh

#$CATALINA_HOME/bin/starup.sh

Verifying the Simple Application Operation

Verify that the simple application operates properly to ensure that the connection between Tomcat to MySQL and Oracle is operational by opening a browser and entering the following website:

http://<YOUR_HOSTNAME>:8080/SimpleDemo/hibernate.jsp

The OSMS Hibernate Test web page is displayed as shown in Figure 14.

Figure 14 Verifying the Simple Application Configuration

Installing, Configuring, and Managing Web Server Middleware Stack Components 41