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!

share this post

Share on twitter
Share on facebook
Share on linkedin
Share on email
 let's have a proper conversation contact us

let's have a proper conversation

more to explore

2021 has been an eventful year!

We’re looking back and reflecting on everything we’ve achieved this year. Thank you to everyone who has worked with us this year. We’ve been fortunate

One person standing in a warehouse, surrounded by professional lights, audio equipment, and cameras. This is part of Creative agency, Colonel Duck's Video Production in Birmingham with BVSC to capture real life stories.

productions

we create and deliver captivating content that audiences engage with.

Two computers next to each other, one showing a web application, created by software agency Colonel Duck, called Pre Enrolment, and the other with software related code

systems

we build and evolve robust platforms that people want to use.

The BBC live streaming one of the Multiple Disadvantage day events, a choir singing, in Birmingham Grand Central Station.

campaign

we design and manage effective campaigns that exceed set targets

info@colonelduck.co.uk
0121 426 3776
Studio 2, Weekin Works
112-116 Park Hill Road
Birmingham
B17 9HD

This site uses cookies: Find out more.