Bye Bye Hibernate – Discovering alternate options to Hibernate in Kotlin | Weblog | bol.com

We’re additionally capable of give JOOQ our area mannequin and let it routinely determine the mapping from the question into the area mannequin. JOOQ can do routinely match this based mostly on current JPA annotations within the area mannequin, the “best-matching constructor” or a customized mapper you present your self.

In our challenge we solely used the metadata constants, whereas JOOQ has extra to supply. JOOQ additionally generates DAO’s as an illustration. We investigated implementing the generated DAO’s in our challenge, however they included default strategies that we thought-about not helpful. For example, a way was generated to search for experiments by (alphabetic) vary of speculation. It appears this ‘choose by vary’ is generated for all fields and creates muddle.

Apart from, the generated DAO code doesn’t appear to take indexes under consideration. A lot of the queries would result in a full desk scan in the event that they have been used, which may closely influence efficiency. We see room for enchancment right here: JOOQ may use the indexes as an indicator of whether or not there’s any use case for the code and depart a extra concise DAO. This is among the causes we focussed our efforts on utilizing the metadata constants.

Our conclusion about JOOQ:

  • JOOQ’s documentation is elaborate and makes the framework straightforward to make use of. Particularly in case you have an current database schema or plan on utilizing a database migration software like Flyway.
  • The metadata constants is usually a good type-safe question implementation, based mostly in your current database. Due to this we have been capable of implement JOOQ with minimal boilerplate code relating to mappings to the information entry layer.
  • JOOQ is actively maintained with month-to-month releases and is essentially the most used ORM framework after Hibernate inside bol.com.
  • One extra notice is that JOOQ has a number of paid variations, that provide a wider vary of supported database dialects and extra options. Our database sort, Postgres, amongst different widespread ones are supported within the open-source model. Fashionable databases like Oracle and SQL Server are solely supported within the paid variations.

Noteworthy point out: Krush

The additional added boilerplate in mapping between the area mannequin and the desk mannequin with Uncovered and Ktorm inspired us to search for another, onto which we encountered Krush.

Krush is predicated on Uncovered and claims to be “a light-weight persistence layer for Kotlin based mostly on Uncovered SQL DSL.”. It removes the necessity for boilerplate mappings by including again JPA annotations to the area mannequin, which we’re used to from Hibernate.

Sadly, there is no such thing as a utilization of this framework inside bol.com and on GitHub the group additionally appears too small to contemplate for utilization in manufacturing. Due to this, we concluded that we might not go to the extent of testing its behaviour. As an alternative, we’ll give Krush a detailed look once in a while to see the way it develops.

Noteworthy point out: Spring JDBC

You may not want all of the complexity that Hibernate/JPA has to supply. Switching to a special ORM framework altogether might be heavy as nicely. What if there would simply be a less complicated different within the ecosystem you might be already utilizing? One such different is obtainable in all Spring initiatives: Spring JDBC!

Spring JDBC will give you a extra low-level strategy, based mostly on JDBC immediately. This is usually a good strategy for smaller initiatives that need to write native queries.


Becoming a member of forces within the bol.com hackathon to analyze Hibernate alternate options in Kotlin was enjoyable and we discovered loads concerning the obtainable alternate options on the market. Our largest studying is that there are 4 main methods of approaching the ORM world:

  • Database schema first, the strategy that JOOQ takes.
  • SQL DSL first, the strategy that Uncovered and KTORM take.
  • JPA annotations first, the strategy that Hibernate and Krush take.
  • Low degree, the strategy that Spring JDBC takes.

All these approaches include their very own set of benefits and downsides. For our use case JOOQ may very well be an alternative choice to Hibernate in our Kotlin initiatives. JOOQ would enable us to change ORM frameworks with minimal adjustments and most type-safety, whereas retaining boilerplate at a minimal. The group and utilization additionally appear ok to undertake the framework for utilization inside a manufacturing surroundings.

It is very important notice that doing a migration from one ORM framework to a different is a heavy course of that wants devoted time to make it work, together with efficiency exams. Hibernate is usually a legitimate ORM framework alternative in a challenge. We hope that you’re now extra conscious of a number of the different frameworks you’ll be able to select from and the way they work.

1 Through the hackathon the challenge staff additionally reserved a small period of time to analyze alternate options for Hibernate Envers. Utilizing a special ORM framework then Hibernate can pose a problem once you nonetheless need to have such out of the field auditing obtainable, as Hibernate Envers can solely be utilized in mixture with Hibernate itself. The conclusion of the small investigation was that Javers promised to be an appropriate different, though this framework appears solely maintained by one individual. Alternatively, you might use a extra low-level strategy through the use of database triggers that audit and log adjustments.

2 Some time in the past Sander spent hours making an attempt to debug issues that have been associated to utilizing information lessons with Hibernate, which ultimately led him to the listed article and repository. An instance of such an issue is that the appliance tried to delete an object from the database, however by means of Hibernates magic below the hood the thing was recreated after the deletion in the identical transaction, leading to no object being deleted. Utilizing the most effective practices from the listed article led to constant outcomes.

Leave a Reply

Your email address will not be published. Required fields are marked *