Use Hibernate without any DB installation

In this article we are going to discuss how can we use hibernate for our development/POC/Unit testing purpose wihout installing any db like Oracle SQL/MySQL etc. 

Here we will use H2 db which does not require any manual installation in our local system. 

Let see what actually we need to do. In the POM.xml of our Java maven project, just add below dependencies. 

One is for H2 and another is for Hibenate. 

 

Now, let do congfiguration in hibernate.cfg.xml file. Below are the details. 

 

Configuration is ready, lets write some code to test it.

And below is our output, as we can see here, without installing any heavy db application we are able to create table and insert data into it.

this code will work for Java 7 without any issue, for greater version you may face errors.





Note : Please comment below for any improvement , suggestions, regarding any wrong information present in this article. We will improve it so that only right information available in this article.




Comments