2
respostas

08 Auto Schema update (opcional) - Erro ao executar a classe TesteJPA

persistence.xml:

<persistence-unit name="contas-postgres">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>br.com.caelum.financas.modelo.Conta</class>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/contas" />
        <property name="javax.persistence.jdbc.user" value="postgres" />
        <property name="javax.persistence.jdbc.password" value="password of super user" />
        <!-- property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" DEPRECATED -->
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
    </properties>
</persistence-unit>

Classe conta.java: foi adicionado o codigo abaixo:

private BigDecimal saldo;

public BigDecimal getSaldo() {
    return saldo;
}

public void setSaldo(BigDecimal saldo) {
    this.saldo = saldo;
}

Classe TesteJpa.java

conta.setSaldo(new BigDecimal(2342.22)); conta.setTitular("Maria dos Santos");

    /**
     * Usando PostgreSQL
     */
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("contas-postgres");

erro:

INFO: HHH000396: Updating schema out 29, 2018 3:37:31 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 0, SQLState: 42703 out 29, 2018 3:37:31 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: ERROR: column t1.tgconstrname does not exist Position: 113 out 29, 2018 3:37:31 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute ERROR: HHH000299: Could not complete schema update java.lang.NullPointerException at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(DatabaseMetadata.java:129) at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:1133) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:212) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:503) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750) at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:94) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905) 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.financas.jpa.TesteJPA.main(TesteJPA.java:29)

Hibernate: select nextval ('SEQ_CONTAS') Hibernate: insert into Conta (agencia, banco, numero, saldo, titular, id) values (?, ?, ?, ?, ?, ?)

2 respostas

alguem tem alguma idéia do porque deste erro?

Bom dia Leonardo, pelo erro que estourou na tela parece que deu algum null pointer! Você pode colar os códigos completos dos trechos que colocou na pergunta pra mim por favor??