Ainda não tem acesso? Estude com a gente! Matricule-se
Ainda não tem acesso? Estude com a gente! Matricule-se
1
resposta

Error creating bean with name 'entityManagerFactory'

1. Erro apresentado:

*13:29:48.455 [main] INFO org.springframework.boot.devtools.restart.RestartApplicationListener - Restart disabled due to System property 'spring.devtools.restart.enabled' being set to false

2022-04-29 13:29:51.279 INFO 159549 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect 2022-04-29 13:29:51.448 ERROR 159549 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.forum.code.modelo.Topico.respostas[com.forum.code.modelo.Resposta] 2022-04-29 13:29:51.448 WARN 159549 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.forum.code.modelo.Topico.respostas[com.forum.code.modelo.Resposta] 2022-04-29 13:29:51.662 WARN 159549 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DBCLOSEONEXIT=FALSE" to the db URL) [90121-200] 2022-04-29 13:29:51.663 INFO 159549 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2022-04-29 13:29:51.669 INFO 159549 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2022-04-29 13:29:51.675 INFO 159549 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2022-04-29 13:29:51.702 INFO 159549 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2022-04-29 13:29:51.740 ERROR 159549 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.forum.code.modelo.Topico.respostas[com.forum.code.modelo.Resposta]

2. Application.properties

-> datasource :

spring.datasource.driver-class-name=org.h2.Driver spring.datasource.url=jdbc:h2:mem:forum-alura spring.datasource.username=sa spring.datasource.password=

-> jpa :

spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=update

-> h2 :

spring.h2.console.enabled=true spring.h2.console.path=/h2-console

3. pom.xml - dependências org.springframework.boot spring-boot-starter-web

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime    </scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

**4. Código  do Java -**![Código Java - classe](https://cdn1.gnarususercontent.com.br/1/1176926/14b778e4-eee9-44d4-a6d6-fee5933818c0.png)  
1 resposta

Oi Fernando,

O Erro: nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.forum.code.modelo.Topico.respostas[com.forum.code.modelo.Resposta]

Sua entidade JPA Resposta deve estar sem a anotação @Entity. Verifica isso.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software