2
respostas

[Dúvida] Falha na conexão com MySql

jan. 16, 2024 10:38:21 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
jan. 16, 2024 10:38:21 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
jan. 16, 2024 10:38:21 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
jan. 16, 2024 10:38:21 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
jan. 16, 2024 10:38:22 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
jan. 16, 2024 10:38:22 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
jan. 16, 2024 10:38:22 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
jan. 16, 2024 10:38:22 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/livrariadb]
jan. 16, 2024 10:38:22 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {password=****, autocommit=true, release_mode=auto, user=root}
jan. 16, 2024 10:38:22 AM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
WARN: HHH000342: Could not obtain connection to query metadata : Unable to load authentication plugin 'caching_sha2_password'.
jan. 16, 2024 10:38:22 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
jan. 16, 2024 10:38:22 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
jan. 16, 2024 10:38:22 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
jan. 16, 2024 10:38:22 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Exception in thread "main" java.lang.ExceptionInInitializerError
    at br.com.caelum.livraria.dao.PopulaBanco.main(PopulaBanco.java:17)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: livraria] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at br.com.caelum.livraria.dao.JPAUtil.<clinit>(JPAUtil.java:10)
    ... 1 more
Caused by: org.hibernate.HibernateException: Error applying BeanValidation relational constraints

    
    #########################################
    
        <persistence-unit name="livraria" transaction-type="RESOURCE_LOCAL">

           <provider>org.hibernate.ejb.HibernatePersistence</provider>
        
        <class>br.com.caelum.livraria.modelo.Livro</class>
        <class>br.com.caelum.livraria.modelo.Autor</class>

        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/livrariadb" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />

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

</persistence>
    
    ###########################################################

Imagem do MySQL

2 respostas

Olá, Adriano! Como vai?

A mensagem de erro "Unable to load authentication plugin 'caching_sha2_password'" indica que o driver do MySQL em uso não suporta o plugin de autenticação 'caching_sha2_password', que é o padrão a partir do MySQL 8.0. Desde o MySQL 8.0.4, houve uma transição do plugin de autenticação padrão do servidor MySQL de 'mysql_native_password' para 'caching_sha2_password'.

Para resolver essa questão, tente executar os passos abaixo:

  1. No prompt de comando (cmd), no diretório que contém o bin do MySQL (por exemplo, "C:\Program Files\MySQL\MySQL Server 8.0\bin"), execute o seguinte comando:

    mysql -u root -p

    Será solicitada a autenticação. Insira seu usuário e senha.

  2. Em seguida, execute o comando a seguir:

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'sua_senha';
    

    Substitua 'sua_senha' pela senha real do usuário root. Depois disso, tente reconectar-se ao banco de dados.

Espero que essas instruções ajudem a resolver o problema.

Abraços e bons estudos!

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓. Bons Estudos!

Bom dia, Monalisa O erro mudou.

jan. 17, 2024 7:41:32 AM org.hibernate.annotations.common.Version INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} jan. 17, 2024 7:41:32 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.1.8.Final} jan. 17, 2024 7:41:32 AM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found jan. 17, 2024 7:41:32 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist jan. 17, 2024 7:41:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) jan. 17, 2024 7:41:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 jan. 17, 2024 7:41:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: true jan. 17, 2024 7:41:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/livrariadb] jan. 17, 2024 7:41:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: {password=****, autocommit=true, release_mode=auto, user=root} jan. 17, 2024 7:41:33 AM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure WARN: HHH000342: Could not obtain connection to query metadata : java.lang.ClassCastException: class java.math.BigInteger cannot be cast to class java.lang.Long (java.math.BigInteger and java.lang.Long are in module java.base of loader 'bootstrap')