skip to Main Content

I have no idea why I see this error on my code.

I was tryed almost everything but there is still error

(This is not a part of problem description but i need to add some more text so i add this stupid comment to can update me post :/.
This is still not enought but i have no idea what more about it i can say and probles is fixed (in the comments is answer))

Code:

package com.example.carsharing.repository.entity;

import javax.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;



@Entity
@Table(name = "CAR")
@Data
@NoArgsConstructor
public class Car {
  @Id
  @GeneratedValue
  @Column(name = "ID")
  Long ID;
  @Column(name = "car_name")
  String carName;
  @Column(name = "company_id")
  Long companyId;



  public Car(long ID, String carName, long companyId) {
      this.ID = ID;
      this.carName = carName;
      this.companyId = companyId;
  }
}

> Error starting ApplicationContext. To display the condition evaluation
> report re-run your application with 'debug' enabled.
> 2023-07-21T17:00:49.296+02:00 ERROR 3872 --- [           main]
> o.s.boot.SpringApplication               : Application run failed
> 
> **org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carRepository' defined in
> com.example.carsharing.repository.carRepository defined in
> @EnableJpaRepositories declared on Main: Not a managed type: class
> com.example.carsharing.repository.entity.Car**    at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:967)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:941)
> ~[spring-context-6.0.10.jar:6.0.10]   at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608)
> ~[spring-context-6.0.10.jar:6.0.10]   at
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
> ~[spring-boot-3.1.1.jar:3.1.1]    at
> org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436)
> ~[spring-boot-3.1.1.jar:3.1.1]    at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
> ~[spring-boot-3.1.1.jar:3.1.1]    at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
> ~[spring-boot-3.1.1.jar:3.1.1]    at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
> ~[spring-boot-3.1.1.jar:3.1.1]    at
> com.example.carsharing.Main.main(Main.java:24) ~[classes/:na]
> **Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.example.carsharing.repository.entity.Car**     at
> org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.managedType(JpaMetamodelImpl.java:192)
> ~[hibernate-core-6.2.5.Final.jar:6.2.5.Final]     at
> org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:467)
> ~[hibernate-core-6.2.5.Final.jar:6.2.5.Final]     at
> org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:97)
> ~[hibernate-core-6.2.5.Final.jar:6.2.5.Final]     at
> org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:80)
> ~[spring-data-jpa-3.1.1.jar:3.1.1]    at
> org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:69)
> ~[spring-data-jpa-3.1.1.jar:3.1.1]    at
> org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:246)
> ~[spring-data-jpa-3.1.1.jar:3.1.1]    at
> org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:211)
> ~[spring-data-jpa-3.1.1.jar:3.1.1]    at
> org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:194)
> ~[spring-data-jpa-3.1.1.jar:3.1.1]    at
> org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:81)
> ~[spring-data-jpa-3.1.1.jar:3.1.1]    at
> org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:317)
> ~[spring-data-commons-3.1.1.jar:3.1.1]    at
> org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:279)
> ~[spring-data-commons-3.1.1.jar:3.1.1]    at
> org.springframework.data.util.Lazy.getNullable(Lazy.java:245)
> ~[spring-data-commons-3.1.1.jar:3.1.1]    at
> org.springframework.data.util.Lazy.get(Lazy.java:114)
> ~[spring-data-commons-3.1.1.jar:3.1.1]    at
> org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:285)
> ~[spring-data-commons-3.1.1.jar:3.1.1]    at
> org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:132)
> ~[spring-data-jpa-3.1.1.jar:3.1.1]    at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1816)
> ~[spring-beans-6.0.10.jar:6.0.10]     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766)
> ~[spring-beans-6.0.10.jar:6.0.10]     ... 15 common frames omitted ```

2

Answers


  1. Chosen as BEST ANSWER

    This is the answear posting by Turing85

    In case Car is annotated with @Entity, please ensure that it uses the correct Entity annotation (for spring-boot 2.x, it should come from package javax; for spring-boot 3.x, it should come from package jakarta). – Turing85


  2. Too hard to go to the link. But you are probably missing an @Entity annotation on Car

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search