Procurei em todos os comentários aqui, mas não encontrei a solução.
- A versão do JDK é a 20.
- Não consegui instalar a versão 8 na minha maquina.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
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_2.xsd">
<persistence-unit name="dados" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dados?useTimezone=true&
serverTimezone=UTC"/>
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="********" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8DialectInnoDBDialect" />
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
package br.com.alura.loja.testes;
import br.com.alura.loja.modelo.Produto;
import org.example.Main;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.math.BigDecimal;
public class CadastroDeProdutos {
public static void main(String[] args){
Produto celular = new Produto();
celular.setNome("Xiomi Redmi");
celular.setDescricao("Muito legal");
celular.setPreco( new BigDecimal("800"));
EntityManagerFactory factory = Persistence.createEntityManagerFactory("loja");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
em.persist(celular);
em.getTransaction().commit();
em.close();
}
}
[Fatal Error] :10:115: The entity name must immediately follow the '&' in the entity reference. Exception in thread "main" javax.persistence.PersistenceException: Unable to locate persistence units at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:85) at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at br.com.alura.loja.testes.CadastroDeProdutos.main(CadastroDeProdutos.java:21) Caused by: javax.persistence.PersistenceException: Unexpected error parsing [file:/C:/Users/raborges/Documents/Java/ConstruindoPortifolio/primeiroProjeto/target/classes/META-INF/persistence.xml] at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:450) at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:249) at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:240) at org.hibernate.jpa.boot.internal.PersistenceXmlParser.doResolve(PersistenceXmlParser.java:234) at org.hibernate.jpa.boot.internal.PersistenceXmlParser.locatePersistenceUnits(PersistenceXmlParser.java:68) at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:81) ... 5 more Caused by: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 115; The entity name must immediately follow the '&' in the entity reference. at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:262) at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:342) at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:445) ... 10 more