Tuesday, April 19, 2022

java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.entity.Customer

I tried to add couple of new entity classes in my project, service implementation and repository for those entity. Once after all done I tried to run my application, my IDE show up to below exception to me.


"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepo' defined in com.example.demo.repo.CustomerRepo defined in @EnableJpaRepositories declared on DemoApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.entity.Customer"

Here my Repo and Customer class

public interface CustomerRepo extends JpaRepository<Customer, Integer> {
}
public class Customer {
private Integer id;
private String name;
private String mobile;
private String email;
}

Its clearly says Customer class is not able to manage by JpaRepository. So JPA not able to consider this Customer class as entity. Because I used Customer class in Repo class as JpaRepository. 

Here the mistake is I forget to change the POJO to Entity. I missed to annotate Customer class with @Entity.


@Entity
@Table(name= "customer", schema = "public")
public class Customer {

So we need to add @Entity annotation to tell jpa this is a entity class to resolve 
this error.

This solve the above exception.

No comments:

Post a Comment