Hibernate does not connect to MySql database

0

Hello,

I needed to take on the development of a servlet that was in someone else's hands. The same is contained in a Tomcat server and must connect to a MySql database to store data of users registered in their forms.

The problem is that I can not get the application to connect to the database. Of the procedures I've already taken to verify that the bank really is online were:

-Connect to the same via MySql Workbench. It occurs normally and I can change data in the database tables.

- Certify if the MySql services were running.

- Certify if the bank server was listening on localhost: 3306 (using telnet)

- Create a basic project with hibernate just to test if I could connect. Yes I did, both with hibernate and with pure JDBC. The difference was only that the dependency versions (connector, hibernate-core and etc) were the most current ones while in the problematic project they are older versions.

Below the persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="PatentePI">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql:3306//localhost/sgpatentes?useTimezone=true&amp;serverTimezone=UTC" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />

            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
        </properties>
    </persistence-unit>

</persistence>

The stacktrace is too large to put it whole here:

2018-05-01 09:13:18,659 INFO  [org.hibernate.annotations.common.Version] HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
2018-05-01 09:13:18,669 INFO  [org.hibernate.Version] HHH000412: Hibernate Core {4.2.4.Final}
2018-05-01 09:13:18,673 INFO  [org.hibernate.cfg.Environment] HHH000206: hibernate.properties not found
2018-05-01 09:13:18,675 INFO  [org.hibernate.cfg.Environment] HHH000021: Bytecode provider name : javassist
2018-05-01 09:13:18,978 INFO  [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] HHH000402: Using Hibernate built-in connection pool (not for production use!)
2018-05-01 09:13:18,983 INFO  [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] HHH000115: Hibernate connection pool size: 20
2018-05-01 09:13:18,984 INFO  [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] HHH000006: Autocommit mode: true
2018-05-01 09:13:18,984 INFO  [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/sgpatentes?useTimezone=true&serverTimezone=UTC]
2018-05-01 09:13:18,984 INFO  [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] HHH000046: Connection properties: {user=root, password=****, autocommit=true, release_mode=auto}
2018-05-01 09:13:19,306 WARN  [org.hibernate.engine.jdbc.internal.JdbcServicesImpl] HHH000342: Could not obtain connection to query metadata : Could not create connection to database server.
2018-05-01 09:13:19,320 INFO  [org.hibernate.dialect.Dialect] HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-05-01 09:13:19,336 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] HHH000422: Disabling contextual LOB creation as connection was null
2018-05-01 09:13:19,611 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
2018-05-01 09:13:19,619 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] HHH000397: Using ASTQueryTranslatorFactory
2018-05-01 09:13:20,155 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] HHH000228: Running hbm2ddl schema update
2018-05-01 09:13:20,155 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] HHH000102: Fetching database metadata
2018-05-01 09:13:20,159 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] HHH000319: Could not get database metadata
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

...

Caused by: java.lang.NullPointerException
    at com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3276)
    at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1940)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1866)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1252)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
    ... 124 more
2018-05-01 09:13:20,164 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] 
HHH000299: Could not complete schema update
    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

...

Caused by: java.lang.NullPointerException
    at com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3276)
    at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1940)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1866)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1252)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
    ... 124 more
Hibernate: select usuario0_.id as id1_4_, usuario0_.cep as cep2_4_, usuario0_.documento as document3_4_, usuario0_.email as email4_4_, usuario0_.endereco as endereco5_4_, usuario0_.fax as fax6_4_, usuario0_.nome as nome7_4_, usuario0_.qualificacao as qualific8_4_, usuario0_.senha as senha9_4_, usuario0_.telefone as telefon10_4_, usuario0_.vinculo as vinculo11_4_ from usuario usuario0_ where lower(usuario0_.email)=?
2018-05-01 09:13:20,513 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] SQL Error: 0, SQLState: 08001
2018-05-01 09:13:20,513 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] Could not create connection to database server.

Dependencies are managed by Maven. Below the pom.xml excerpt of persistence:

<!-- Núcleo do Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.4.Final</version>
            <scope>compile</scope>
        </dependency>

        <!-- Implementação de EntityManager da JPA -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.2.3.Final</version>
            <scope>compile</scope>
        </dependency>

        <!-- Driver JDBC do MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
            <scope>compile</scope>
        </dependency> 

IDE: eclipse EE Oxygen.3a Release (4.7.3a) OS: Windows 10 MySql Server: 8.0.11 X64 TomCat ver. 7.0.86

I'm fairly new to hibernate and javaEE. I am trying to understand the work that someone else has done, if anyone can give me tips I can do in this case, I am very grateful.

    
asked by anonymous 01.05.2018 / 14:50

0 answers