Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The "java.lang.IllegalArgumentException: Not a managed type" error occurs when Spring is unable to recognize an entity as a managed type. This can happen when:

  • The entity is not annotated with the @Entity annotation.
  • The package in which the entity is located is not scanned by Spring.
  • The entity is not registered with the persistence context.

To resolve this issue, you can try the following:

  1. Make sure that the entity is annotated with @Entity annotation.

  2. Ensure that the package containing the entity is being scanned by Spring. You can do this by either adding @ComponentScan(basePackages = "package.name") to your application main class or adding @EntityScan(basePackages = "package.name") to your configuration.

  3. If you are using Spring Data JPA, make sure your repository interfaces are properly annotated with @Repository and extend the correct Spring Data repository.

  4. Check that your entity class is included in your persistence.xml file.

  5. Verify that you have the correct dependencies and version numbers for Spring and Spring Data in your build.gradle or pom.xml file.

By following the above steps, you should be able to resolve the "java.lang.IllegalArgumentException: Not a managed type" issue and run your Spring Boot 2 application successfully with @Entity and @Repository.