Sunday, February 15, 2015

Hibernate Tutorial using Gradle Build System

Hibernate Tutorial using Gradle Build Tool

In this Tutorial, we'll be walking through on how to setup the Hibernate Project using Gradle Build System.

Step1: File -> New -> Other -> Gradle Project -> Give the name for the Project -> Finish.

Step2 : Our Project Structure would be now looking as below

Step 3: Now let's start with the creation of Config File (.cfg.xml) at src/main/resources directory along with the Hibernate Configuration Console (this helps in validating our connection against db)

i) .cfg.xml Creation

Select src/main/resources/org/gradle directory -> Right Click -> Hibernate Configuration File -> Give the name for .cf.xml -> Click Next and we will get the Window. Fill the Connection details as below.

We ought to make sure if Create Console Configuration option is checked at bottom as shown in picture above -> Click Next

ii) Console Configuration Creation

Once we click Next in above Window, we'll be taken towards another dialog to fill in the details for Console Configuration as shown below:

In the Main Tab, provide the Hibernate Version value as 4.0 and proceed to Options Tab.

In the Options Tab, provide the Database Dialect value as Oracle 10g and move to Classpath Tab.

In the Classpath Tab, click the button Add External jar and add the ojdbc jar as below and click Finish

Step 4: We gonna save objects into the Table named person having a column named id. So Let's create a POJO named Person with a variable named id.