hn.today

Dissecting Spring petclinic (Part 2 – Bending the persistence)

hannomalie.github.io3 points0 comments
Screenshot of Dissecting Spring petclinic (Part 2 – Bending the persistence)

The author replaces Spring Data and Hibernate in Spring Petclinic with JDBI, SQL, and plain Java objects to make persistence and test data more explicit. The change responds to tests whose expected results depend on fixtures hidden in configuration or SQL files, making it hard to see what each test arranges and verifies. Replacing container-generated repositories with custom ones proved cumbersome: Spring configuration and bean wiring caused duplicate definitions and injection failures, and test data had to be maintained separately for different database setups. Removing entity relationships also required redesigning view models that had relied on nested owner, pet, and visit collections. Java records seemed attractive for simpler data models, but their immutability and conversion requirements made them awkward in this project.

The SQL migration itself was mostly direct, but translating Hibernate queries sacrificed portability and convenience, and the normal application setup developed unresolved connection failures. Writing persistence logic by hand exposed work previously handled by JPA: upserts, generated IDs, database-specific return types, and keeping SQL property lists aligned with table columns. A simple save operation grew into conditional update-and-insert logic. The experiment shows that Spring’s persistence tools impose constraints and can hide important behavior, but they also perform substantial necessary work. JDBI offers more direct control and potentially clearer data handling, yet pure SQL brings significant mapping and maintenance costs. The author concludes that the changes have not improved the project overall; they are a step toward a more data-centered design.

Read on hannomalie.github.io0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Sarasa Gothic Mono

Sarasa Gothic Mono

Sarasa Gothic Mono is a free, open-source monospace typeface built for multilingual programming, combining Source Han Sans and Iosevka. It offers coding ligatures, pixel-friendly hinting, condensed characters, and support for Latin, Cyrillic, Greek, and East Asian scripts. (picaq.github.io)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.