Setting up Hibernate
In this article let’s see how to setup development environment to use hibernate framework with eclipse.
Step1 :
- Download hibernate jar files: which are required to use hibernate framework. You can download latest version of hibernate jar files from:http://hibernate.org/orm/downloads/
- Extract zip file that you downloaded. Inside extracted files:
- You can find hibernate-core-5.0.0.Beta2 which is main jar file that is required to use hibernate library.
- “Lib” folder: contains jars that hibernate requires. It has dependencies of hibernate. Jars that are essential are in the ‘required’ folder and we will also use JPA jar(you can find it within “jpa” folder)
Step 2:
- Open your eclipse: Let’s create new java project with name “FirstHibernateProject”
- Right click on project select properties. Within properties go to Java build path and select libraries tab.
- You can create new library with all required jars, so that you don’t have add jar files each when you are working with hibernate. You can just include this library whenever you are working with hibernate
- To create new library:
- Click on Add Library tab and select user library.
- Click on new and specify library name and click Ok.
- I have created library with name hibernate (Refer below picture).
- After creating library, the next step is to add jar files. Click on “Add JARs”. Select main jar file, required and JPA jar files from extracted files. Click on ok.
- Select user library that you created and click on finish
- Now you can see that hibernate library is added to your project with all the required jars.
Step 3:
- Before configuring hibernates, prerequisites are:
- You must have database installed in your machine. So that, we can configure hibernate to connect to database. You can have any database available and configure hibernate to connect to database.
- Hibernate internally uses JDBC driver to connect to database. So depending on database, you have to provide hibernate the JDBC driver, So that it can use that driver to connect to database.
- Add your JDBC jar file to a project (Got o properties->Java build path-> libraries-> Add external jars): This will help hibernate to connect to database that you have installed in your machine.
Step 4:
- If you want to change hibernate configuration to another database, you will have to do two things:
- Install database in your machine.
- Provide JDBC for that database to hibernate.
This is all the ground work required to configure project that uses hibernate.
We created project, added hibernate jars and JDBC for the database.
Now you are all set to write code that uses hibernate.
Leave a Reply