1
resposta

Executei o teste da lição 8 e deu erro. Abri o MariaDB e não vi a tabela.

abr 21, 2020 5:38:46 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named contas
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at br.com.alura.testes.TesteCriaTabelas.main(TesteCriaTabelas.java:9)
1 resposta

Para inicializar a JPA, é preciso definir um arquivo de configuração, chamado persistence.xml:

<?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" version="2.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
   <persistence-unit name="alura">
      <class>br.com.alura.jpa.modelo.Conta</class>
      <properties>
         <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
         <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/alura_jpa?serverTimezone=UTC" />
         <property name="javax.persistence.jdbc.user" value="root" />
         <property name="javax.persistence.jdbc.password" value="" />
         <property name="hibernate.hbm2ddl.auto" value="update" />
         <property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect" />
         <property name="hibernate.show_sql" value="false" />
         <property name="hibernate.format_sql" value="true" />
      </properties>
   </persistence-unit>
</persistence>

Esse arquivo deve ser criado no diretório "src/main/resources/META-INF/"