Hibernate Project Setup
Initial Setup
- Copy hibernate_template_project under your workspace folder.
- From IDE:
- Click on File --> Import --> Maven --> Existing Maven Project
- Browse and select hibernate_template_project --> Finish.
- Update the project:
- Right click on the project --> Maven --> Update Project
- Select Force update checkbox --> Finish
- 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
- Add @Entity and @Id annotations
- Add other required annotations
- Add
<mapping>
entry in hibernate.cfg.xml
8. Run TestHibernate Again
This will test automatic table creation.
9. Copy Supplied Tester