h1

Setting Up and Using Hibernate

In order to use Hibernate in a Java Application there are several things you must do.  This tutorial is designed to help you use Hibernate in a standard Java application being created using eclipse.

Things to do once:

  • Install the JBoss Hibernate tools.  Use the Help->Install New Software pulldown.
  • click Add
  • Call the new site Hibernate
  • set the URL to http://download.jboss.org/jbosside/updates/development/
  • Select only the Hibernate tools for installation when presented with the selection dialog.

Things to do each time you start a new project:

  1. Create a standard Java project
  2. Add the hibernate jar files to the project buildpath
    • All of the files in the <<Eclipse installation>>/plugins/org.hibernate.eclipse_<<version number>>/lib/hibernate directory
    • All of the files in the <<Eclipse installation>>/plugins/org.hibernate.eclipse_<<version number>>/lib/annotations directory
  3. Add the HibernateUtilSingleton.java file to your project’s src directory and change its package name
  4. Add the log4j.properties file to your project’s src directory
  5. Add the MySQL jdbc driver jar file to the build path
  6. Create and add your POJO (Plain Old Java Object) classes representing the database tables to your src directory
  7. Add the @Entity, @Table, @Id, and @GeneratedValue annotations to each of your POJO classes
  8. Add the @OneToMany, @JoinTable, and @JoinColumn to your POJO classes that need one-to-many relationships with other POJO classes so that they reflect the database relationships

Leave a Comment