Most developers misuse @Transactional and don’t even realize it 👇 At first, I thought adding @Transactional everywhere would make my code “safe”. It doesn’t. Here’s what actually happens: ❌ Transaction won’t work on private methods ❌ Internal method calls skip Spring proxy ❌ Rollback doesn’t trigger for checked exceptions by default Example mistake: Calling a transactional method inside the same class → No transaction applied Why? 👉 Spring uses proxies, not direct method execution What I do now: ✅ Keep transactions in service layer ✅ Avoid internal method calls ✅ Understand rollback behavior Small annotation. Big production bugs if misunderstood. Save this before your next backend issue. What’s a mistake you learned the hard way? 👇 #SpringBoot #Java #BackendDevelopment #CleanCode #SoftwareEngineering
Smit Pataliya’s Post
More Relevant Posts
-
Your @Transactional might not be working… and Spring won’t warn you. 🚨 I’ve seen this bug more than once: Code looks correct. @Transactional is there. But rollback never happens. Why? 👇 Because Spring transactions work through proxies. That means: Calling a @Transactional method from another method inside the SAME class = Transaction won’t apply. No error. No warning. Just silent failure. Other common traps 👇 → Checked exceptions don’t trigger rollback by default → Private methods won’t be proxied → Async calls break transaction boundaries What I always check 👇 ✔ Is the transactional method being called through Spring proxy? ✔ Is rollback configured for the right exception type? ✔ Are transaction boundaries placed at the service layer? @Transactional is powerful… But dangerous when assumed instead of understood. Framework annotations are not magic. They still follow rules. Have you ever debugged a transaction issue that “should have worked”? 👇 #Java #SpringBoot #Transactional #SpringFramework #BackendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
Spent 20 minutes wondering why my @Transactional wasn't rolling back. The code looked fine: @Service public class PaymentService { @Transactional public void processPayment() { savePayment(); throw new Exception("Something went wrong"); } } Exception thrown. But the payment was still saved. The problem: @Transactional only rolls back on unchecked exceptions by default. Exception is checked. RuntimeException is unchecked. The fix: @Transactional(rollbackFor = Exception.class) Or throw a RuntimeException instead. Small detail. Big consequence. #SpringBoot #Java #Transactions #BackendDevelopment
To view or add a comment, sign in
-
Most developers think @Autowired is just dependency injection. It's not ❌ It's Reflection + Proxies + Runtime Wiring. Which means : ⭕ Dependencies are injected at runtime (not compile time) ⭕ You might be calling a proxy, not your actual class ⭕ Field injection hides dependencies and hurts testability ⭕ Startup time increases as your app grows The biggest surprise : 👉 this.method() can bypass Spring logic completely (broken @Transactional) Lesson : "Convenience annotations often hide real complexity." Do you still use Field Injection in production ? #SpringBoot #Java #BackendEngineering #SoftwareArchitecture
To view or add a comment, sign in
-
Day 95 of my consistency journey Today was all about going deeper into building my URL Shortener project and strengthening my backend fundamentals. I focused on understanding how real-world systems handle redirection, database interaction, and scalability. Instead of just coding, I tried to think like a backend engineer — why things are designed a certain way, not just how. 💡 Key takeaways from today: - How URL redirection actually works behind the scenes - Importance of clean architecture in backend systems - Thinking in terms of scalability from the start - Strengthening Java + Spring Boot fundamentals Consistency is slowly turning confusion into clarity. Still a long way to go, but showing up every day is the real win. #Day95 #Consistency #BackendDevelopment #Java #SpringBoot #SystemDesign #100DaysOfCode
To view or add a comment, sign in
-
-
⚠️ Why @Transactional Sometimes Doesn’t Work in Spring Boot A common mistake: Calling a @Transactional method from another method inside the SAME class. Result? Transaction doesn’t trigger. Why? Because Spring uses proxies. Internal method calls bypass the proxy, so transaction management never happens. Fix: → Move logic to another service OR → Call through Spring-managed bean Small detail. Big production issue. #springboot #java #backendengineering
To view or add a comment, sign in
-
-
𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 — 𝗗𝗮𝘆 𝟯 Day 3 was where things started getting more real. This section focused on the core concepts of the Spring Framework — the things that actually make Spring powerful behind the scenes. The total duration was around 2 hours 18 minutes, but again, it took me 1 week to properly understand and connect everything. Here’s what I learned: 🔹 What a Web Framework is 🔹 Introduction to Spring Framework 🔹 Tight Coupling vs Loose Coupling (with hands-on) 🔹 Core concepts of Spring (Java Web Development basics) 🔹 Spring Container & Configuration 🔹 Setting up a Spring project 🔹 Beans in Spring • Creating your first Bean • Bean Lifecycle 🔹 Dependency Injection (DI) • Constructor Injection • Setter Injection 🔹 Inversion of Control (IoC) 🔹 Autowiring • By Name • By Type • By Constructor Understanding concepts like Dependency Injection and IoC really changed how I think about writing code. It’s less about creating everything manually and more about letting Spring manage things efficiently. Also, concepts like loose coupling finally started making practical sense when I saw them in code. 📌 Next part coming soon. #SpringBoot #JavaDeveloper #BackendDevelopment #LearningJourney #Day3 #TechGrowth #Consistency
To view or add a comment, sign in
-
Clean code in backend development is not about making code look “smart.” It’s about making it easy to understand, maintain and debug. A few practices that improve code quality in Java backend applications: - use meaningful class and method names - keep methods focused on a single responsibility - avoid hardcoded values and magic numbers - write reusable and modular business logic - handle exceptions consistently - keep controllers thin and move logic to services - remove unused code instead of leaving commented blocks In production systems, readable code saves time during debugging, onboarding and incident handling. Code is written once but read many times. #Java #BackendDevelopment #CleanCode #SpringBoot #SoftwareEngineering
To view or add a comment, sign in
-
Spring doesn’t just create beans- it manages their entire lifecycle. Many developers stop at "@Autowired", "@Qualifier", and "@Primary". But to build reliable and production-ready applications, understanding the Spring Bean Lifecycle is essential. ------ 🧠 What happens behind the scenes? A Spring bean goes through multiple stages: • Instantiation • Dependency Injection • Initialization (e.g., "@PostConstruct") • Ready for use • Destruction (e.g., "@PreDestroy") ------ 🔥 Key idea: • "@PostConstruct" → Used for initialization after dependencies are injected • "@PreDestroy" → Used for cleanup before the bean is destroyed ----- 💡 Why this matters: Proper lifecycle management helps you: ✔ Avoid resource leaks ✔ Manage connections effectively ✔ Write cleaner and more maintainable code ✔ Build stable, production-ready applications ----- 🎯 Best practice: Avoid placing heavy logic (such as database calls) inside constructors. Instead, use lifecycle annotations to handle initialization and cleanup in a structured way. ----- 📌 Takeaway: If your Spring knowledge ends at dependency injection, you’re only scratching the surface. 👉 Understanding the lifecycle is what separates good developers from great ones. #SpringBoot #SpringFramework #JavaDeveloper #BackendDevelopment #SoftwareEngineering #CleanCode #CodingBestPractices #LearnInPublic #Developers #Java
To view or add a comment, sign in
-
-
Is it a 6 or a 9? 👀 Two people. Same number. Different perspectives. In software development, I see this all the time: Frontend says it’s a bug. Backend says it’s working fine. Both are right — from their side. The real problem? Missing clarity. ✔ Align on the same data ✔ Check logs, payloads, contracts ✔ Remove ambiguity Because good engineering is not about arguing who is right — it’s about making things clear enough that no one has to argue. Have you faced this in your project? 🤔 #Angular #Java #Debugging #SoftwareEngineering #TeamWork
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