
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:
- ⁃ Create a standard Java project
- 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
- Add the HibernateUtilSingleton.java file to your project’s src directory and change its package name
- Add the log4j.properties file to your project’s src directory
- Add the MySQL jdbc driver jar file to the build path
- Create and add your POJO (Plain Old Java Object) classes representing the database tables to your src directory
- Add the @Entity, @Table, @Id, and @GeneratedValue annotations to each of your POJO classes
- 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