* 目次 [#a2c902a6] #contents * Spring Boot JPA「Not a managed type」エラーの解決記録 [#w03e30c5] ** 概要 [#m121dc85] Spring Boot + Spring Data JPAで「Not a managed type: class ...」エラーが発生し、エンティティがJPAの管理対象にならない問題に遭遇。非常に分かりづらいバグだったため、解決までの流れとポイントを記録する。 ** 発生した現象 [#u681760d] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxRepository' ... Not a managed type: class xxx ** 原因 [#i36fa1ef] - Spring Boot 3.x + JDK 17以降では、`javax.persistence.*` ではなく `jakarta.persistence.*` を使う必要がある。 - エンティティクラスや複合主キー(@Embeddable等)でも全て `jakarta.persistence.*` で統一しないと認識されない。 - 依存ライブラリ(pom.xml)も `jakarta.*` 系が必要。 ** 解決方法 [#g5d3b11a] + エンティティクラス、IDクラスのimportを全て `jakarta.persistence.*` に修正。 + @EntityScanなどの設定パスが正しいか再確認。 + 不要な@Config/@ComponentScan等は削除。 *** 実際の修正例 [#j59299e8] // 修正前 import javax.persistence.Entity; import javax.persistence.Embeddable; // 修正後 import jakarta.persistence.Entity; import jakarta.persistence.Embeddable; ** 感想・教訓 [#e6b10af9] - Spring Boot 3.x以降ではjakarta移行に要注意。 - エラーメッセージだけではimportの違いに気づきにくい。 - 公式ドキュメントやStack Overflowの事例が非常に役立つ。 *** 参考になったサイト [#mdc08d40] https://stackoverflow.com/questions/76174604/spring-data-jpa-unsatisfied-dependency-expressed-error-creating-bean-with-nam