🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

2 @Transactional Traps That Catch Even Senior Java Developers in interviews

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

I have 13 years of Java experience. I have also interviewed hundreds of developers at MNCs.



Two questions about @Transactional that catch even senior developers. Try answering before you scroll down.









Q1: If a non-transactional method calls a @Transactional method in the same class, does the transaction apply?






CODE
@Service
public class OrderService {

public void placeOrder(Order order) {
this.saveOrder(order);
}

@Transactional
public void saveOrder(Order order) {
orderRepository.save(order);
inventoryRepository.update(order);
}
}






Answer: No.



Reason, in plain terms: when you add @Transactional, Spring does not add the transaction logic inside your class. Instead, it creates a second object that sits in front of your class — think of it as a wrapper. Other classes that call saveOrder() (through @Autowired) actually call this wrapper first. The wrapper starts the transaction, then calls your real method, then commits or rolls back.



This wrapper only exists outside your class. So when your own code calls this.saveOrder(order), it skips the wrapper completely and goes straight to the real method. No wrapper means no transaction logic. No rollback if inventoryRepository.update() fails.



This bug never shows up in tests. It only shows up in production, when a failure leaves your data half-updated.



Fix: call the method from a different class, or inject the wrapper of your own class:




CODE
@Service
public class OrderService {

@Autowired
private OrderService self; // this is the wrapper, not the raw object

public void placeOrder(Order order) {
self.saveOrder(order); // now it goes through the wrapper
}

@Transactional
public void saveOrder(Order order) {
orderRepository.save(order);
inventoryRepository.update(order);
}
}












Q2: Does @Transactional roll back on every exception?






CODE
@Transactional
public void processRefund(Order order) throws RefundException {
paymentRepository.markRefunded(order);
externalRefundService.notify(order); // throws RefundException
}






Answer: No.



Reason: by default, @Transactional only rolls back on unchecked exceptions (RuntimeException and its subclasses). RefundException above is a checked exception. So if it is thrown, Spring lets the transaction commit anyway — including the markRefunded write that happened right before the failure.



Fix: tell Spring to roll back on any exception, not just unchecked ones:




CODE
@Transactional(rollbackFor = Exception.class)
public void processRefund(Order order) throws RefundException {
paymentRepository.markRefunded(order);
externalRefundService.notify(order);
}









I cover topics like this in more depth in my guide — Core Java, Java 8 to 21, Multithreading, Spring Boot, Microservices, Design Patterns, and Coding Round Patterns.



Free sample:



Got either one right? Drop it in the comments.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 2 @Transactional Traps That Catch Even Senior Java Developers in interviews

Thematisch verwandte Begriffe: Transactional, Traps, That, Catch · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...