This article concludes our discussion covering the addition of a search service to a Java application. It is excerpted from chapter 10 of the book Better, Faster, Lighter Java, written by Bruce A. Tate and Justin Gehtland (O'Reilly; ISBN: 0596006764).
Adding Hibernate to a Java Application - Changing the Application Configuration (Page 3 of 4 )
In order to get the new DAOs working with jPetStore, we need to modify some configuration files. First, we’ll need to create the global hibernate.properties file, which tells Hibernate which database to use and how to use it. jPetStore is currently configured to use a local instance of Hypersonic SQL, with a username of “sa” and a blank password (NEVER do this in a production environment). The hibernate.properties file looks like this:
This file should be saved in the project root file, next to the other global configuration files. Hibernate will look for it by name.
Next, open upjPetStore’s dataAccessContext-*.xml files (one is dataAccessContext-jta.xml and the other is dataAccessContext-local.xml). In each, there is a section that mapes the DAOs for the project. Change each mapping to point to the new DAO, and eliminate the now unnecessary properties. For example, the original mapping forProductDaowas:
We can eliminate the properties because the Hibernate versions of the DAOs do not require any configuration information to be passed in by the controller; Hibernate manages those issues for us.
Once you have successfully changed all the DAO references, the last remaining piece is to include the necessary jar files in your class path. Hibernate requires the following jars: hibernate2.jar, cglib2.jar, ehcache.jar, commons-collections.jar, dom4j.jar, and jta.jar (all of which are included in the Hibernate download).