Brahma-HibernateUtils: Entity registration in Dropwizard made dead simple

Aashrai Ravooru
GoZefo Engineering
Published in
2 min readJun 12, 2018

--

Dropwizard is a great framework for building backend services, it acts as a connection between popular libraries to jumpstart java applications. But with all these connections comes a lot of boilerplate.

One such ugly boilerplate is the HibernateBundle, where one must register every @Entity class for hibernate to recognise it and for SQL queries to work via the DAO classes. Leading to some nasty looking code in the main application class

What an e-commerce company’s hibernateBundle looks like(exaggerated for dramatic effect!!)

If the really long boilerplate wasn’t annoying enough, you only get to know about an @Entity class you forgot to register at runtime with some facepalm exceptions in your logs.

ERROR API_EXCEPTION UnexpectedException: org.hibernate.UnknownEntityTypeException: Unable to locate persister: com.client.model.PorterHouseSteak
A clap if you know why I used this GIF after the stacktrace

If boilerplate and runtime exceptions make you sad, us folks at Gozefo Engineering have got your back!! Presenting Brahma-HibernateUtils an open source library which uses the power of annotation processing in java to keep track of @Entity classes for you. Making your hibernateBundle initialisation as simple as:

Brahma_HibernateUtils.java is where your Entity classes at

Brahma_HibernateUtils.java is a generated class with a list of all classes with an @Entity annotation, making it super easy to register them.

All classes with an Entity annotation end up in the entityAnnotatedClasses array

Brahma-HibernateUtils is 100% open source and we welcome all kinds of pull requests and help with the docs.

If you love programming and destroying java boilerplate Gozefo Engineering is hiring!!.

--

--