Why you should use Hibernate

Why you should use Hibernate

My name is Mike Gregory, I am known for my love of burgers, 80s hair styles and my constant harping on about simple code (K.I.S.S. anyone?).

This week as part of our ongoing effort to improve our knowledge in Systems I gave a presentation about the Hibernate framework.

What is Hibernate?

Hibernate is an object-relational mapping tool for the Java programming language. Essentially it provides a front-end for your database that is object-orientated rather than relational. This way you can work with Java objects, but you can make them persistent by storing them in, or loading them from your database.

Why use it?

When writing code in an object-orientated language such as Java, it is often useful to store your data in a database. Popular relational databases such as MySQL and PostgreSQL offer a robust and powerful way to store and interact with data, however there can be a mismatch between the relational way of doing things and object-orientated paradigms that can add unwanted complexity to applications.

ORM (Object-Relational Mapping) is a way to provide an object orientated front-end for the database, with the aim of simplifying your data model. The idea is that you can think purely in terms of objects, and come up with more elegant solutions to problems rather than having to juggle responsibilities between an object-orientated and relational way of thinking.

Why are Colonel Duck interested in it?

· Anything that simplifies our solutions is good in my book. When using relational databases in Java you have two separate ways of organising your data, the persistent relational layer, and the malleable Java object layer. If we can think of solutions purely in terms of objects, we can write elegant solutions with simple architectures which will mean less bugs!

· Prettier code. I’m sure anyone who reads code all day will agree, pretty code is easier on the eyes. Hibernate can allow us to remove lots of JDBC boilerplate code as well as largely automating CRUD (Create, read, update, delete) operations.

· Again, less bugs! Having less or no SQL code in our Java methods. SQL code is a common source of application errors due to the Java compiler and IDEs not being able to automatically warn you about errors as they can with Java code.

· Lower-coupling. Hibernate is database independent, so if we need to change our database software we can easily.

There are many other reported benefits, and TutorialsPoint has a good guide on getting started here.

I am always interested in anything that complements the KISS principle (Keep It Simple Stupid), as it’s very easy for code to get complicated even without the added concern of how to link your Java objects to your relational database.
This is just one stepping stone on my quest to create simple, robust code and eat delicious burgers!


Why you should use Hibernate was originally published in Quacking tips on Medium, where people are continuing the conversation by highlighting and responding to this story.

“Why you should use Hibernate” Posted first on ” Programming on Medium “
Author: Colonel Duck Productions

Author: Pawan Kumar

Leave a Reply

Close Menu
%d bloggers like this:
Skip to toolbar