@Transactional を付けたのにロールバックされない2つの原因:同じクラス内からの呼び出しとチェック例外
一括登録の処理で例外が出たのに、途中まで登録したデータがデータベースに残っていました。登録のメソッドには @Transactional を付けています。 調べると、ロールバックされない原因は2つありました。どちらもエラーは出ず、テストで例外の発生だけを確かめていると気付けません。 ...
一括登録の処理で例外が出たのに、途中まで登録したデータがデータベースに残っていました。登録のメソッドには @Transactional を付けています。 調べると、ロールバックされない原因は2つありました。どちらもエラーは出ず、テストで例外の発生だけを確かめていると気付けません。 ...
Spring Boot のバージョンを上げたところ、コードは何も変えていないのに、起動時に次のエラーが出るようになりました。 *************************** APPLICATION FAILED TO START *************************** Description: The dependencies of some of the beans in the application context form a cycle: ┌─────┐ | inventoryService (field private com.example.demo.OrderService com.example.demo.InventoryService.orderService) ↑ ↓ | orderService (field private com.example.demo.InventoryService com.example.demo.OrderService.inventoryService) └─────┘ Action: Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true. 結論:Spring Boot 2.6 から、Bean 同士の循環参照が既定で禁止されました。 2.5 までは Spring が自動で循環を解決していたので、昔から循環していたコードがバージョンアップで表に出ます。設定で以前の動きに戻せますが、本来は循環そのものをなくします。 ...