Home arrow Java arrow Page 5 - Installation and Set Up of Hibernate
JAVA

Installation and Set Up of Hibernate


Hibernate is an object/relational mapping service that bridges the worlds of Java objects and relational databases. If this sounds like it might be useful to you, keep reading. This article is excerpted from chapter one of Hibernate A Developer's Notebook, written by James Elliot (O'Reilly; ISBN: 0596006969).

Author Info:
By: O'Reilly Media
Rating: 4 stars4 stars4 stars4 stars4 stars / 8
July 27, 2006
TABLE OF CONTENTS:
  1. · Installation and Set Up of Hibernate
  2. · Getting an Ant Distribution
  3. · Getting the HSQLDB Database Engine
  4. · Getting Hibernate
  5. · Setting Up a Project Hierarchy
  6. · Setting Up a Project Hierarchy: A quick test

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Installation and Set Up of Hibernate - Setting Up a Project Hierarchy
(Page 5 of 6 )

Although we’re going to start small, once we start designing data structures and building Java classes and database tables that represent them, along with all the configuration and control files to glue them together and make useful things happen, we’re going to end up with a lot of files. So let’s start out with a good organization from the beginning. As you’ll see in this process, between the tools you’ve downloaded and their supporting libraries, there are already a significant number of files to organize.

Why do I care?

If you end up building something cool by following the examples in this book, and want to turn it into a real application, you’ll be in good shape from the beginning. More to the point, if you set things up the way we describe here, the commands and instructions we give you throughout the examples will make sense and actually work. Many examples alsobuild on one another throughout the book, so it’s important to get on the right track from the beginning.

If you want to skip ahead to a later example, or just avoid typing some of the longer sample code and configuration files, you can download “finished” versions of the chapter examples from the book’s web site. These downloads will all be organized as described here.

How do I do that?

Here's how:

  1. Pick a location on your hard drive where you want to play with Hibernate, and create a new folder, which we’ll refer to from now on as your project directory
  2. Move into that directory, and create subdirectories calledsrc,lib, anddata. The hierarchy of Java source and related resources will be in thesrc directory. Our build process will compile it into aclasses directory it creates, as well as copy any runtime resources there. Thedata directory is where we’ll put the HSQLDB database, and any Data Definition Language (DDL) files we generate in order to populate it.

    Thelib directory is where we’ll place third-party libraries we use in the project. For now, copy the HSQLDB and Hibernate JAR files into thelib directory.
  3. If you haven’t already done so, expand the HSQLDB distribution file you downloaded earlier in this chapter. You’ll findhsqldb.jar in itslib directory; copy this to your own projectlib directory (thelib directory you just created in step 2).
  4. Similarly, locate thelib directory in the Hibernate directory you expanded in the previous section, and copy all of its contents into your own projectlib directory (you’ll notice that Hibernate relies on a lot of other libraries; conveniently, they’re included in its binary distribution so you don’t have to hunt them all down yourself). 
  5. Then copy Hibernate itself, in the form of thehibernate2.jar file found at the top level of the distribution, into your projectlib directory. 
  6.  Installing the Hibernate Extensions is very similar. Locate thetools/lib directory inside the Hibernate Extensions directory you expanded, and copy its contents into your ownlib directory, so the extensions will be able to access the libraries they rely on.
  7. Finally, copy the extensions themselves, which are in the filehibernate-tools.jar (found in thetools directory), into yourlib directory.

    There are lots of pieces to copy into place here; attention to detail will be rewarded. Luckily, you can reuse your lib directory in other Hibernate projects.

  8. The example classes we’re going to create are all going to live in thecom.oreilly.hh (harnessing Hibernate) package, so create these directories under thesrc directory. On Linux and Mac OS X, you can use:

      mkdir -p src/com/oreilly/hh

    from within your project directory to accomplish this in one step.

    At this point your project directory should be structured as shown in Figure 1-1.

            
    Figure 1-1.  Initial project directory contents

The lib directory is collapsed because it contains so much that the screen shot wouldn’t fit otherwise. After following the above steps, using the release of Hibernate available at the time of this writing, it contains the following files:

README.txt, ant-1.5.3.jar, ant-optional-1.5.3.jar, apache.license.txt, c3p0-
0.8.3.jar, c3p0.license.txt, cglib-2.0-rc2.jar, commons-collections-2.1.jar,
commons-dbcp-1.1.jar, commons-lang-1.0.1.jar, commons-logging-1.0.3.jar, commons-pool-1.1.jar, concurrent-1.3.2.jar, connector.jar, connector. licence.txt, dom4j-1.4.jar, ehcache-0.6.jar, hibernate-tools.jar, hibernate2.jar, hsqldb.jar, jaas.jar, jaas.licence.txt, jboss-cache.jar, jboss-common.jar, jboss-jmx.jar, jboss-system.jar, jcs-1.0-dev.jar, jdbc2_0-
stdext.jar, jdbc2_0-stdext.licence.txt, jdom.jar, jdom.license.txt, jgroups-
2.2.jar, jta.jar, jta.licence.txt, junit-3.8.1.jar, log4j-1.2.8.jar, odmg-3.
0.jar, oscache-2.0.jar, proxool-0.8.3.jar, swarmcache-1.0rc2.jar, xalan-2.4.
0.jar, xerces-2.4.0.jar, xml-apis.jar.


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials