<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44" -->

---
title: Spring Boot: Build URL Shortener Application - Part 3:...
description: A hands-on walkthrough builds the data layer of a Spring Boot URL shortener, covering Spring Data JPA fundamentals, switching from H2 to PostgreSQL, three...
canonical: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Spring Boot: Build URL Shortener Application - Part 3: Working with Spring Data JPA | daily.dev
og:description: A hands-on walkthrough builds the data layer of a Spring Boot URL shortener, covering Spring Data JPA fundamentals, switching from H2 to PostgreSQL, three...
og:url: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44
og:image: https://api.daily.dev/og/posts/DwKXI7v44.png
og:image:alt: Spring Boot: Build URL Shortener Application - Part 3: Working with Spring Data JPA
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Spring Boot: Build URL Shortener Application - Part 3: Working with Spring Data JPA

**[SivaLabs \(YouTube\)](https://daily.dev/sources/sivalabs-youtube)** · 54 min read · 0 upvotes · 0 comments

## Summary

A hands-on walkthrough builds the data layer of a Spring Boot URL shortener, covering Spring Data JPA fundamentals, switching from H2 to PostgreSQL, three database initialization approaches (JPA ddl-auto, schema/data SQL scripts, and Flyway migrations), generating entities and repositories with IntelliJ IDEA Ultimate, writing derived and JPQL queries, layering controller/service/repository code, rendering results with Thymeleaf, and using Spring Boot's Docker Compose support to auto-start a PostgreSQL container during local development.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=1XAf6BK_8lg>

## Questions this post answers

### What are the different ways to initialize a database schema in a Spring Boot application with Spring Data JPA?

There are three common approaches: using spring.jpa.hibernate.ddl-auto (create, update, or validate) to generate tables from entity classes, which is convenient but unsuitable for production since it can't rename columns or create stored procedures and views; using schema.sql and data.sql files with spring.sql.init.mode set to always, embedded, or never, though these rerun on every restart causing errors like duplicate tables; or using Flyway migrations, which track applied scripts in a flyway_schema_history table with checksums so each versioned script runs only once.

_Developers choosing a schema strategy for Spring Boot apps can compare these approaches further on daily.dev._

### Why does spring.jpa.hibernate.ddl-auto=update fail to rename a column when I rename a field in my JPA entity?

Setting ddl-auto to update only adds new columns based on entity changes; it never renames or drops existing ones. Renaming a field from isPrivate to privateOnly in the entity and restarting with update causes Hibernate to create a new privateOnly column while leaving the original is_private column untouched, resulting in duplicate, inconsistent columns rather than a clean rename.

_Anyone debugging unexpected schema drift in JPA entities can dig into similar Spring Data JPA gotchas on daily.dev._

### How does Spring Boot's Docker Compose support automatically configure a PostgreSQL data source for local development?

Adding the spring-boot-docker-compose dependency along with a compose.yaml file (defining a postgres:17 service, for example) lets the application automatically start the container on launch and configure the PostgreSQL data source properties at runtime, overriding any manually set values. By default containers stop when the app stops, but setting Docker Compose lifecycle management to 'start_only' keeps them running in the background; this support is excluded from the packaged jar and is meant only for local development.

_Developers wiring up local Postgres containers for Spring Boot can explore this workflow further on daily.dev._

## Similar posts on daily.dev

- [Spring Data JDBC Made Easy with IntelliJ IDEA](https://daily.dev/posts/spring-data-jdbc-made-easy-with-intellij-idea-kqz5h1shs) · JetBrains · 0 upvotes · 0 comments

---

Tags: [#postgresql](https://daily.dev/tags/postgresql), [#spring](https://daily.dev/tags/spring), [#spring-boot](https://daily.dev/tags/spring-boot), [#docker-compose](https://daily.dev/tags/docker-compose)

[View this post on daily.dev](https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Spring Boot: Build URL Shortener Application - Part 3: Working with Spring Data JPA","url":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44"},"datePublished":"2026-09-27T07:26:36.988Z","dateModified":"2026-09-27T07:53:36.298Z","description":"A hands-on walkthrough builds the data layer of a Spring Boot URL shortener, covering Spring Data JPA fundamentals, switching from H2 to PostgreSQL, three...","image":"https://i.ytimg.com/vi/1XAf6BK_8lg/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/1XAf6BK_8lg/sddefault.jpg","isAccessibleForFree":true,"articleSection":"SivaLabs (YouTube)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SivaLabs (YouTube)","logo":"https://media.daily.dev/image/upload/s--8ATVo4an--/f_auto,q_auto/v1790493987/logos/sivalabs-youtube?_a=BAMAMicg0","url":"https://daily.dev/sources/sivalabs-youtube"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"postgresql,spring,spring-boot,docker-compose","timeRequired":"PT54M","video":{"@type":"VideoObject","name":"Spring Boot: Build URL Shortener Application - Part 3: Working with Spring Data JPA","description":"A hands-on walkthrough builds the data layer of a Spring Boot URL shortener, covering Spring Data JPA fundamentals, switching from H2 to PostgreSQL, three...","thumbnailUrl":"https://i.ytimg.com/vi/1XAf6BK_8lg/sddefault.jpg","uploadDate":"2026-09-27T07:26:36.988Z","duration":"PT54M","url":"https://api.daily.dev/r/DwKXI7v44","embedUrl":"https://www.youtube.com/embed/1XAf6BK_8lg"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SivaLabs (YouTube)","item":"https://daily.dev/sources/sivalabs-youtube"},{"@type":"ListItem","position":3,"name":"Spring Boot: Build URL Shortener Application - Part 3: Working with Spring Data JPA"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-3-working-with-spring-data-jpa-dwkxi7v44#faq","mainEntity":[{"@type":"Question","name":"What are the different ways to initialize a database schema in a Spring Boot application with Spring Data JPA?","acceptedAnswer":{"@type":"Answer","text":"There are three common approaches: using spring.jpa.hibernate.ddl-auto (create, update, or validate) to generate tables from entity classes, which is convenient but unsuitable for production since it can't rename columns or create stored procedures and views; using schema.sql and data.sql files with spring.sql.init.mode set to always, embedded, or never, though these rerun on every restart causing errors like duplicate tables; or using Flyway migrations, which track applied scripts in a flyway_schema_history table with checksums so each versioned script runs only once. Developers choosing a schema strategy for Spring Boot apps can compare these approaches further on daily.dev."}},{"@type":"Question","name":"Why does spring.jpa.hibernate.ddl-auto=update fail to rename a column when I rename a field in my JPA entity?","acceptedAnswer":{"@type":"Answer","text":"Setting ddl-auto to update only adds new columns based on entity changes; it never renames or drops existing ones. Renaming a field from isPrivate to privateOnly in the entity and restarting with update causes Hibernate to create a new privateOnly column while leaving the original is_private column untouched, resulting in duplicate, inconsistent columns rather than a clean rename. Anyone debugging unexpected schema drift in JPA entities can dig into similar Spring Data JPA gotchas on daily.dev."}},{"@type":"Question","name":"How does Spring Boot's Docker Compose support automatically configure a PostgreSQL data source for local development?","acceptedAnswer":{"@type":"Answer","text":"Adding the spring-boot-docker-compose dependency along with a compose.yaml file (defining a postgres:17 service, for example) lets the application automatically start the container on launch and configure the PostgreSQL data source properties at runtime, overriding any manually set values. By default containers stop when the app stops, but setting Docker Compose lifecycle management to 'start_only' keeps them running in the background; this support is excluded from the packaged jar and is meant only for local development. Developers wiring up local Postgres containers for Spring Boot can explore this workflow further on daily.dev."}}]}
```

