Maintaining Java ORM Code
Reviewed by Greg Wilson / 2016-04-26
Keywords: Maintenance
Chen2016 Tse-Hsun Chen, Weiyi Shang, Jinqiu Yang, Ahmed E. Hassan, Michael W. Godfrey, Mohamed Nasser, and Parminder Flora: "An empirical study on the practice of maintaining object-relational mapping code in Java systems". Proceedings of the 13th International Conference on Mining Software Repositories, 10.1145/2901739.2901758.
Despite the advantages of using ORM [object-relational mapping] frameworks, we observe several difficulties in maintaining ORM code (i.e., code that makes use of ORM frameworks) when cooperating with our industrial partner. After conducting studies on other open source systems, we find that such difficulties are common in other Java systems. Our study finds that i) ORM cannot completely encapsulate database accesses in objects or abstract the underlying database technology, thus making ORM code changes more scattered; ii) ORM code changes are more frequent than regular code, but there is a lack of tools that help developers verify ORM code at compilation time; iii) changes to ORM code are more commonly due to performance or security reasons; however, traditional static code analyzers need to be extended to capture the peculiarities of ORM code in order to detect such problems. Our study highlights the hidden maintenance costs of using ORM frameworks, and provides some initial insights about potential approaches to help maintain ORM code. Future studies should carefully examine ORM code, in particular given the rising use of ORM in modern software systems.
I wasn't surprised to find that ORMs can't completely encapsulate database access, but I was surprised to learn that the result is scattered code changes. I was even more surprised to find that changes to ORM code are more common than changes to "regular" code, but that's one of the reasons to read research: to find out where personal experience is atypical of general practice. And I hope the authors of various IDEs take the third point to heart: PyCharm's ability to debug Django templates saved me days of tedious debugging (at least), and similar support for debugging ORM code might have saved me even more.