ORM in Java: A Love-Hate Relationship

In the world of Java development, one topic that has sparked debate and frustration for many developers is Object-Relational Mapping (ORM). ORM is a technique used to bridge the gap between object-oriented programming languages, such as Java, and relational databases, like MySQL or PostgreSQL. The purpose of ORM is to simplify the data access layer and eliminate the need for developers to write raw SQL queries.


However, a recent text expressing strong criticism of ORM on Java, particularly Hibernate, has garnered attention among developers. The author claims that ORM, in general, has always been a disappointing solution. One of the arguments presented is that the ability to use different databases, which was once touted as a selling point of ORM, is a feature that is rarely utilized in practice. Furthermore, the claim that developers don’t need to know SQL while using ORM is dismissed as false, as modifying queries at the string level is often necessary in non-trivial applications.

The author asserts that the proper way to build a data layer is by writing one query at a time as a string, with string interpolation. They advocate for a closer integration with raw JDBC (Java Database Connectivity), stating that the closer developers are to raw JDBC, the better their data layer will be. The “Domain Model” concept, which is often associated with ORM, is also criticized as being void of any logic, and therefore an ineffective approach.

One alternative to traditional ORM that is praised in the text is the use of query builders such as Slonik. These tools provide many of the features typically associated with an ORM, such as automatic binding of results to objects and strong type checking, while still allowing developers to write normal SQL queries. The author argues that learning SQL is a more valuable skill than learning the custom query languages of ORM tools.

While there are differing opinions on ORM, it is important to note that ORMs serve a purpose in specific contexts. They can be useful for simplifying CRUD (create, read, update, delete) operations and reducing boilerplate code. However, when it comes to more complex database operations or optimizing performance, using raw SQL queries or query builders may be a preferred approach.

It is also worth mentioning that there are well-regarded ORMs available for Java, such as Hibernate, that have proven to be valuable tools for many developers. These ORM frameworks provide rich features and have been extensively tested and optimized. The decision to use an ORM or not ultimately depends on the specific requirements of a project and the preferences of the development team.

In conclusion, the debate surrounding ORM in Java continues to spark discussions and contrasting opinions among developers. While some criticize its limitations and argue for a closer integration with raw SQL, others appreciate the productivity and convenience that ORM frameworks provide. As with any technology, it is important for developers to evaluate their specific needs and make informed decisions about the tools they use.

Disclaimer: Don’t take anything on this website seriously. This website is a sandbox for generated content and experimenting with bots. Content may contain errors and untruths.