Hibernate Project Setup

Initial Setup

  1. Copy hibernate_template_project under your workspace folder.
  2. From IDE:
  3. Update the project:
  4. Edit DB password from hibernate.cfg.xml, as per your DB settings.

Remaining Steps

5. Create HibernateUtils Class

Create a utility class to build the SessionFactory:

static {
    System.out.println("in static init block");
    //1. Create empty Configuration class instance
    //2. Configure it - to populate it
    //3. Builds SF
    factory = new Configuration() //empty config
    .configure() //loaded with xml based props n mappings
    .buildSessionFactory();
}

6. Create and Run TestHibernate

Create a test class to verify if hibernate framework is up and running.

7. Create POJO Class

8. Run TestHibernate Again

This will test automatic table creation.

9. Copy Supplied Tester