Bom dia !
Estou tentando replicar o programa da aula, e estão acontecendo muitas exceptions, estou usando o banco postgress.
public class CadastroDeProduto {
public static void main(String[] args) {
Categoria celulares = new Categoria("CELULARES");
Produto celular = new Produto("Xiaomi Redmi", "Muito legal", new BigDecimal("800"), celulares );
EntityManager em = JPAUtil.getEntityManager();
ProdutoDAO produtoDao = new ProdutoDAO(em);
CategoriaDAO categoriaDao = new CategoriaDAO(em);
em.getTransaction().begin();
categoriaDao.cadastrar(celulares);
produtoDao.cadastrar(celular);
em.getTransaction().commit();
em.close();
}
}
Hibernate: create table categorias (id bigserial not null, nome varchar(255), primary key (id)) jul. 29, 2022 8:18:28 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException WARN: GenerationTarget encountered exception accepting command : Error executing DDL "create table categorias (id bigserial not null, nome varchar(255), primary key (id))" via JDBC Statement org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table categorias (id bigserial not null, nome varchar(255), primary key (id))" via JDBC Statement at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277) at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207) at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:184) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:316) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:469) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1259) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at br.com.alura.lojaJPA.util.JPAUtil.(JPAUtil.java:11) at br.com.alura.lojaJPA.testes.CadastroDeProduto.main(CadastroDeProduto.java:20) Caused by: org.postgresql.util.PSQLException: ERROR: relation "categorias" already exists at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:406) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:398) at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ... 16 more
Ele gera estes conflitos dizendo que as tabelas e colunas já existem, ao meu ver aparentemente criar ou alterar tabelas via JPA, da muito conflito com o banco, não estou conseguindo entender o que fazer.