Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Conexão com Postgresql

Boa tarde!

Tentei fazer a conexão com o Postgresql, porém recebo uma exception...

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.myorgtech</groupId>
    <artifactId>pratica-jpa</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.6.9.Final</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.4.0</version>
        </dependency>
    </dependencies>

</project>
<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="pratica-jpa" transaction-type="RESOURCE_LOCAL">

        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> 
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/pratica-jpa" /> 
            <property name="javax.persistence.jdbc.user" value="admin" /> 
            <property name="javax.persistence.jdbc.password" value="admin" /> 

            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/> 
            <property name="hibernate.hbm2ddl.auto" value="update" /> 

            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
        </properties>

    </persistence-unit>

</persistence>

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

1 resposta
solução!

Consegui resolver utilizando uma configuração diferente no arquivo xml

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/pratica-jpa</property>
        <property name="connection.username">myOrg</property>
        <property name="connection.password">myPass</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL10Dialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <!-- Log session statistics -->
        <property name="hibernate.generate_statistics">true</property>

        <!-- Names the annotated entity classes -->
        <mapping class="com.myorgtech.loja.modelo.Categoria"/>
        <mapping class="com.myorgtech.loja.modelo.Produto"/>

        </session-factory>
        </hibernate-configuration>

Criei apenas um arquivo na pasta "resources" com o nome de "hibernate.cfg.xml", com as configurações acima.