6
respostas

[Dúvida] Problema na criação da tabela series com jpa

2024-03-12T21:32:28.470-03:00 INFO 7956 --- [Series] [ main] br.com.alura.Series.SeriesApplication : Starting SeriesApplication using Java 17.0.10 with PID 7956 (C:\Users\Public\Rafael\Series\Series\target\classes started by BEIT in C:\Users\Public\Rafael\Series\Series) 2024-03-12T21:32:28.474-03:00 INFO 7956 --- [Series] [ main] br.com.alura.Series.SeriesApplication : No active profile set, falling back to 1 default profile: "default" 2024-03-12T21:32:29.097-03:00 INFO 7956 --- [Series] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2024-03-12T21:32:29.123-03:00 INFO 7956 --- [Series] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14 ms. Found 0 JPA repository interfaces. 2024-03-12T21:32:29.627-03:00 INFO 7956 --- [Series] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2024-03-12T21:32:30.058-03:00 INFO 7956 --- [Series] [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@5f038248 2024-03-12T21:32:30.060-03:00 INFO 7956 --- [Series] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2024-03-12T21:32:30.144-03:00 INFO 7956 --- [Series] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2024-03-12T21:32:30.248-03:00 INFO 7956 --- [Series] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.4.Final 2024-03-12T21:32:30.323-03:00 INFO 7956 --- [Series] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled 2024-03-12T21:32:30.353-03:00 INFO 7956 --- [Series] [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final} 2024-03-12T21:32:30.794-03:00 INFO 7956 --- [Series] [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer 2024-03-12T21:32:31.504-03:00 INFO 7956 --- [Series] [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration) 2024-03-12T21:32:31.511-03:00 INFO 7956 --- [Series] [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2024-03-12T21:32:31.767-03:00 INFO 7956 --- [Series] [ main] br.com.alura.Series.SeriesApplication : Started SeriesApplication in 3.794 seconds (process running for 4.626)

Não cria a tabela no banco alura_series.

Meu arquivo aplication.properties spring.datasource.url=jdbc:postgresql://localhost:5432/alura_series

spring.datasource.username=postgres spring.datasource.password=senha spring.datasource.driver-class-name=org.postgresql.Driver hipernate.dialect=org.hibernate.dialect.HSQLDialect

Depentências no pom.xml org.springframework.boot spring-boot-starter

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
       
    </dependency>
    
    <dependency>
         <groupId>com.theokanning.openai-gpt3-java</groupId>
         <artifactId>service</artifactId>
         <version>0.14.0</version>
    </dependency>
    

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.5.6.Final</version>
    </dependency>
    
<dependency>
6 respostas

Oi, Rafael! Tudo bem?

Ali na parte das propriedades, no application.properties, você digitou hipernate.dialect. Troca pra hibernate.dialect e vê se vai criar o banco. Acho que é só esse errinho de digitação que está atrapalhando!

Espero ter ajudado!

Abraços e bons estudos!

Iasmim obrigado. Realmente digitei errado e corregi. Porém continua com o mesmo problema de não criar a tabela. Abaixo está o resultado na console depois que rodo o sistema.

2024-03-13T22:50:29.317-03:00 INFO 17336 --- [ restartedMain] br.com.alura.Series.SeriesApplication : Starting SeriesApplication using Java 17.0.10 with PID 17336 (C:\Users\Public\Rafael\Series\Series\target\classes started by BEIT in C:\Users\Public\Rafael\Series\Series) 2024-03-13T22:50:29.321-03:00 INFO 17336 --- [ restartedMain] br.com.alura.Series.SeriesApplication : No active profile set, falling back to 1 default profile: "default" 2024-03-13T22:50:29.381-03:00 INFO 17336 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2024-03-13T22:50:30.035-03:00 INFO 17336 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2024-03-13T22:50:30.065-03:00 INFO 17336 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces. 2024-03-13T22:50:30.614-03:00 INFO 17336 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2024-03-13T22:50:30.704-03:00 INFO 17336 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.4.Final 2024-03-13T22:50:30.757-03:00 INFO 17336 --- [ restartedMain] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled 2024-03-13T22:50:30.782-03:00 INFO 17336 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final} 2024-03-13T22:50:31.213-03:00 INFO 17336 --- [ restartedMain] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer 2024-03-13T22:50:31.250-03:00 INFO 17336 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2024-03-13T22:50:31.599-03:00 INFO 17336 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@7fc2e03b 2024-03-13T22:50:31.602-03:00 INFO 17336 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2024-03-13T22:50:32.451-03:00 INFO 17336 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JTA platform [org.hibernate.engine.transaction.jta.platform.internal.BitronixJtaPlatform] 2024-03-13T22:50:32.464-03:00 INFO 17336 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2024-03-13T22:50:32.723-03:00 INFO 17336 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2024-03-13T22:50:32.766-03:00 INFO 17336 --- [ restartedMain] br.com.alura.Series.SeriesApplication : Started SeriesApplication in 3.927 seconds (process running for 4.617) 1 - Buscar séries 2 - Buscar episódios 3 - Listar séries buscadas

0 - Sair

Rafael,

Para criar a tabela no banco tem que adicionar mais uma linha ao arquivo application.properties

spring.jpa.hibernate.ddl-auto=update

Com essa linha o JPA irá criar ou atualizar as tabelas baseado nas Entities que você declarou no projeto.

Eduardo obrigado pela atenção. Já coloquei spring.jpa.hibernate.ddl-auto=update, porém continua não criando as tabelas Será que alguém poderia colocar aqui o seu arquivo pom.xml? Alguém que conseguiu criar a tabela! Desde já obrigado

Oi Rafael, você está versionando esse código no github? Seria mais fácil de tentar entender o problema se desse pra ver o código completo.

Meu pom.xml para o projeto do screenmatch está assim:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>br.com.alura</groupId>
    <artifactId>screenmatch</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>screenmatch</name>
    <description>Primeiro projeto spring sem web</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

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

        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.16.1</version>
        </dependency>

        <dependency>
            <groupId>com.theokanning.openai-gpt3-java</groupId>
            <artifactId>service</artifactId>
            <version>0.18.2</version>
        </dependency>

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

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

E o aplication.properties assim:

##################
# BANCO DE DADOS #
##################
# Define conexão com o banco
spring.datasource.url=jdbc:postgresql://${DB_HOST}/${DB_NAME}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver

# Dialeto do hibernate para JPA
hibernate.dialect=org.hibernate.dialect.HSQLDialect

#Permissão para o jpa atualizar o banco de dados de acordo com as entidades no código
spring.jpa.hibernate.ddl-auto=update

#Para visualizar as operações SQL realizadas pelo JPA
spring.jpa.show-sql=true
spring.jpa.format-sql=true

Eduardo obrigado amigo:

Eu vou comparar os meus arquivos com o seu e se eu não conseguir resolver o problema. Eu passo o código no github.