Bom dia, por favor me ajude a resolver esse erro.
nov. 13, 2022 10:10:46 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
nov. 13, 2022 10:10:46 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1049, SQLState: 42000
nov. 13, 2022 10:10:46 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Unknown database 'loja'
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
.
.
.
Caused by: org.hibernate.exception.SQLGrammarException: Error calling Driver#connect
.
.
.
Caused by: java.sql.SQLSyntaxErrorException: Unknown database 'loja'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
... 29 more
<?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="loja" 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/loja"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="12345678"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL57Dialect"/>
</properties>
</persistence-unit>
</persistence>
4.0.0
br.com.jhonata
loja
0.0.1-SNAPSHOT
org.apache.maven.plugins
maven-compiler-plugin
3.8.0
11
org.hibernate
hibernate-entitymanager
5.4.27.Final
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
package br.com.jhonata.loja;
import java.math.BigDecimal;
import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table;
//Classe entidade ou seja, existe uma tabela no BD que esta mapeando (espelho) dessa classe //Quando quer troca o nome da tabela do BD usa a anotação @Table(name = ""), pois por padrao ela considera o nome da tabela o mesmo q a da classe
@Entity @Table(name = "produtos") public class Produto {
/Quando o nome da coluna for diferente do atributo usa-se @Column(name = "" )/
/Gerar valor id (chave) sequencial/ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
private String nome;
private String descricao;
private BigDecimal preco;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public BigDecimal getPreco() {
return preco;
}
public void setPreco(BigDecimal preco) {
this.preco = preco;
}
`