Pots, kettles and databases by Eduardo Bellani

Sometimes you stumble upon small insights that illuminate a good chunk of things. Recently I think I have stumbled upon what I believe is a case of that, on the Hibernate manual(King 2024), of all places. The author of the manual itself makes it clear that it is a special section of the manual:

In this section, we’re going to give you our opinion. If you’re only interested in facts, or if you prefer not to read things that might undermine the opinion you currently hold, please feel free to skip straight to the next chapter.

The section can be summarized in the following recommendation and image(King 2024):

we’re not sure you need a separate persistence layer at all

Figure 1: Hibernate’s manual suggested architecture

Figure 1: Hibernate’s manual suggested architecture

What I found very interesting is that the core of the author’s point is that it was misguided to believe the following:

Eventually, some folks came to believe that their DAOs shielded their program from depending in a hard way on ORM, allowing them to “swap out” Hibernate, and replace it with JDBC, or with something else. In fact, this was never really true—there’s quite a deep difference between the programming model of JDBC, where every interaction with the database is explicit and synchronous, and the programming model of stateful sessions in Hibernate, where updates are implicit, and SQL statements are executed asynchronously.

But the same argument applies to Hibernate itself! Why call a transaction/Hibernate layer at all? Why not just call directly the DBMS? So that you can swap DBMSes?

The following is an image that I think summarizes this article:

Figure 2: Charles H. Bennett’s coloured engraving from Shadow and Substance (1860), a series based on popular sayings. In this case, a coal-man and chimney sweep stop to argue in the street in illustration of “The pot calling the kettle black”. A street light throws the shadow of the kitchen implements on the wall behind them.

Figure 2: Charles H. Bennett’s coloured engraving from Shadow and Substance (1860), a series based on popular sayings. In this case, a coal-man and chimney sweep stop to argue in the street in illustration of “The pot calling the kettle black”. A street light throws the shadow of the kitchen implements on the wall behind them.

References

King, Gavin. 2024. An Introduction to Hibernate 6. 6.4. https://docs.jboss.org/hibernate/orm/6.4/introduction/html_single/Hibernate_Introduction.html.