If your tests are slow, your learning curve is slow too—H2 can change that today. 🚀 In Spring Boot, H2 is a lightweight in-memory database that starts instantly, making it perfect for repository and integration tests. You get realistic SQL behavior without managing an external DB during development. <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> spring: datasource: url: jdbc:h2:mem:testdb username: sa password: h2: console: enabled: true Use @DataJpaTest to validate repository logic in isolation and catch mapping/query issues early. A great workflow is: H2 for fast local feedback, then PostgreSQL integration tests for production parity. Common pitfall: assuming H2 behaves exactly like PostgreSQL/MySQL in every SQL edge case—it does not. Treat H2 as a speed layer, not your only verification layer. #Java #SpringBoot #BackendDevelopment
Jānis Ošs’ Post
More Relevant Posts
-
4 releases in a weekend: Testcontainers Java module, AWS CLI bundled, Step Functions intrinsics, RDS Data stubs. Free, open-source, MIT licensed. TL;DR We shipped 4 releases this weekend (v1.2.6 through v1.2.9): org.ministack:testcontainers-ministack:0.1.0 on Maven Central 62 bug fixes found by running 2,490 tests across all 41 services AWS CLI bundled in the Docker image — init scripts just work Step Functions intrinsics — 7 new functions (ArrayContains, MathAdd, UUID, etc.) RDS Data API stubs — test database provisioning without Docker-in-Docker https://ministack.org https://lnkd.in/e-RBG-yn
To view or add a comment, sign in
-
-
🚀 New Project: Secure Authentication with Spring Boot I recently built a Login & Registration system and wanted to share the logic behind the scenes! This was a great exercise in handling RESTful APIs and database management. 🧠 The Logic: Registration: Captures user data via POST, validates inputs, and persists it to a MySQL database using Spring Data JPA. Login: Fetches the user by ID/Username and validates credentials. If they match, a success response is sent; otherwise, an error is handled. API Verification: Used Postman to test every edge case—ensuring correct JSON responses and HTTP status codes (200 OK, 401 Unauthorized, etc.). 🛠️ Tech Stack: Java 21 & Spring Boot 3.3.5 MySQL for reliable data storage OpenAPI for easy API exploration Check out the screen recording below to see the UI and "Login Successful" flow! 📽️ 📂 View on GitHub: https://lnkd.in/dbCiX_T4 #Java #SpringBoot #BackendDevelopment #Postman #MySQL #CSStudent #CodingLogic
To view or add a comment, sign in
-
🧠 My Spring Boot API just got a real upgrade today 👀 I implemented full CRUD operations using Spring Boot + JPA 🚀 Here’s what my API can do now 👇 ✅ CREATE → Add new data ✅ READ → Fetch data ✅ UPDATE → Modify existing data ✅ DELETE → Remove data Flow remains clean 👇 Client → Controller → Service → Repository → Database What I used 👇 ✅ Spring Boot ✅ Spring Data JPA ✅ MySQL ✅ REST APIs 💡 My takeaway: This is where backend development starts feeling real — you’re not just reading data, you’re managing it ⚡ #Java #SpringBoot #CRUD #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
The Spring Boot annotation that is silently corrupting your database. If you are a Spring Boot developer, you probably use @Transactional every day. If something fails, the database rolls back. Simple, right? But what happens when you write code like this? @Service public class UserService { // The entry point called by the Controller public void registerUser(UserDTO dto) { // ... some validation logic ... saveUserAndSendEmail(dto); } @Transactional public void saveUserAndSendEmail(UserDTO dto) { userRepository.save(new User(dto.email())); emailService.sendWelcomeEmail(dto.email()); // What if this throws an exception? } } What you think happens: If the email service fails and throws an exception, @Transactional catches it, rolls back the database insert, and the user is not saved. What ACTUALLY happens: The database commits the user anyway. Your system now has a user who never got their welcome email, and your database is in an inconsistent state. Why did it fail? The "Proxy Bypass" Trap. Spring’s @Transactional doesn't work by magic; it works by creating an AOP Proxy around your class. When an outside class (like your Controller) calls your Service, it hits the Proxy first, which opens the database transaction. BUT... if you call a method from within the same class (like registerUser calling saveUserAndSendEmail), you are using the internal this reference. You completely bypassed the Spring Proxy. The transaction never started. The rollback will never happen. The Senior Fixes: 1. The Architecture Fix: Move the @Transactional logic to a separate UserRegistrationService. Calling an external class forces you to go through the proxy. 2. The Simple Fix: Put @Transactional on the entry-point method (registerUser) instead of the internal helper method. Stop assuming annotations are magic. If you don't understand how proxies work under the hood, your data is at risk! Have you ever spent hours debugging a @Transactional rollback that just wouldn't trigger? 👇 #Java #SpringBoot #Hibernate #BackendDevelopment #Microservices #SoftwareEngineering #CleanCode #TechTips #LogicLedaMagic
To view or add a comment, sign in
-
💡 The file upload mistake that would've haunted me in production storing a full URL in your database is a trap. https://lnkd.in/getwKNqc — looks fine. works fine. until you switch storage providers and realize you now have 50,000 rows to update in production. Took me an embarrassing amount of time to figure out the right way: store only the key → users/abc123.jpg keep the base URL in your config combine them at runtime when building responses One env variable change. entire system migrated. database never stores a domain name again. That was just one of three things I got wrong building file uploads this week. The second one: skipping compression. a user uploads a 4MB phone photo, you store a 4MB phone photo. your storage bill is quiet now. it won't be later. compress before upload, not after. a 3MB image should leave your server under 150KB. The third: public storage buckets. if your file URL works forever with no auth, that's not a feature. generate signed URLs with expiry instead. 10 extra lines of code, one less thing to regret. File uploads feel like a solved problem until you actually build one properly. #Java #SpringBoot #BackendDev
To view or add a comment, sign in
-
-
🧬 Spring Boot – Repository Layer & Database Concept Continuing my Spring Boot journey by understanding how applications interact with databases. 🧠 Key Learnings: ✔️ Role of "@Repository" in Spring Boot ✔️ How the repository layer handles data operations ✔️ Flow of application: Controller → Service → Repository → Database 💡 The repository layer acts as a bridge between business logic and the database, making data handling clean and organized. 💻 DSA Practice: • Finding duplicate characters • Sorting an array using basic logic ⌨️ Maintaining daily typing practice to improve speed and accuracy. 🧠 Quick Check: Which layer talks to the database? 👉 Repository ✅ Building a strong foundation in backend development step by step 🚀 #SpringBoot #Java #BackendDevelopment #Database #DSA #LearningInPublic #DeveloperJourney
To view or add a comment, sign in
-
Most developers think Spring handles 500 requests “all at once.” It doesn’t. Here’s what actually happens: Spring Boot (via embedded Tomcat in Spring Boot) uses a thread pool to handle incoming requests. Each request follows this path: → Request arrives at Tomcat → A free thread is assigned → DispatcherServlet routes it to your @RestController → Controller → Service → Database → Response is returned → Thread goes back to the pool That’s it. No magic. ━━━━━━━━━━━━━━━━━━━━ What happens when all threads are busy? → New requests are placed in a queue → If the queue is full, requests may be rejected (e.g., 503 errors depending on configuration) ━━━━━━━━━━━━━━━━━━━━ The real bottleneck isn’t traffic, it’s blocked threads. Consider this: A slow database call takes 3 seconds × 200 threads = Your system can stall under moderate load This is why backend engineers focus on: Thread pool tuning Reducing blocking operations Asynchronous processing (@Async) Efficient database access (connection pooling) Non-blocking architectures (Spring WebFlux) Key takeaway: Performance is not about handling more requests. It’s about how efficiently your threads are utilized. #Java #SpringBoot #Concurrency #BackendDevelopment #SoftwareEngineering #JavaDeveloper
To view or add a comment, sign in
-
🚀 Built a Complete Spring Boot REST API with CRUD Operations I’m excited to share my latest project where I developed a RESTful API using Spring Boot and MySQL. This project demonstrates full CRUD functionality and follows a clean layered architecture. 🔧 Tech Stack: • Spring Boot • Spring Data JPA • MySQL • REST API • RAPID API (Testing) 📁 Architecture: Client → RestController → Service → Repository →Entity-> Database 📌 Features Implemented: ✅ Create Student (POST) ✅ Get All Students (GET) ✅ Get Student By ID (GET) ✅ Update Student (PUT) ✅ Delete Student (DELETE) 🔗 API Endpoints: POST /students GET /students GET /students/{id} PUT /students/{id} DELETE /students/{id} This project helped me understand: • REST API design • Layered architecture • Database integration using JPA • Testing APIs using RAPID API CLIENT Looking forward to feedback and suggestions! #SpringBoot #RESTAPI #Java #MySQL #BackendDevelopment #SpringDataJPA #Learning #CRUD #Developer
To view or add a comment, sign in
-
I thought our Spring Boot API was fast… until we hit 1,000 users Everything worked perfectly in my local environment. But in production, our dashboard became painfully slow. The logs told the real story: Hundreds of SQL queries… for a single request. I had accidentally introduced the infamous N+1 Query Problem. 🔴 The Mistake I was fetching Users and their Orders using "findAll()". Since the relationship was "FetchType.LAZY" (default), Hibernate did this: • 1 query → fetch all Users • N queries → fetch Orders for each User 👉 With 1,000 users = 1,001 database calls for one page load 😬 🟢 The Fix Used "JOIN FETCH" in a custom query: @Query("SELECT u FROM User u JOIN FETCH u.orders") List<User> findAllWithOrders(); This forces Hibernate to fetch everything in a single SQL join. ⚡ The Result • Database calls: 1,001 → 1 • Response time: 5s → <200ms • Server CPU: Stable again 📌 The Lesson Performance issues often hide in “innocent” code. Don’t blindly trust default JPA behavior. Always monitor SQL logs during development — your future self will thank you. Have you ever been bitten by the N+1 problem? What’s your go-to solution — "JOIN FETCH" or "EntityGraph"? #Java #SpringBoot #Hibernate #BackendDevelopment #Performance #DatabaseOptimization #CleanCode
To view or add a comment, sign in
-
Slow queries almost broke our payment system. Here's what fixed it. We had APIs taking 4–5 seconds to respond under high load. The culprit? Unoptimized PostgreSQL queries on a table with millions of rows. What we did: Step 1 — Added indexes on high-frequency query columns → Response time dropped immediately Step 2 — Replaced SELECT * with specific columns → Less data transfer, faster response Step 3 — Used pagination instead of fetching full results → Memory usage dropped significantly Step 4 — Analyzed slow queries using EXPLAIN ANALYZE → Found full table scans we didn't know existed Step 5 — Moved repeated DB calls to cache → DB load reduced by 40% Result: 4–5 seconds → under 500ms response time Same hardware. Same database. Just better queries. Most performance problems are not hardware problems. They are query problems. What's the worst slow query you've debugged? Drop it below 👇 #PostgreSQL #BackendDevelopment #Java #SystemDesign #DatabaseOptimization #SpringBoot #BackendEngineer #immediateJoiner #java
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development