ERROR: column "type" of relation "tb_people" does not exist

1

Hello.

I'm trying to persist a record, but when I run it, it is returning the error below:

// ...
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "tipo", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("P")
public class Pessoa {   
    private Integer id;
    private String nome;
}
// ...
@DiscriminatorValue(value = "F")
@PrimaryKeyJoinColumn(name = "id")
public class PessoaFisica extends Pessoa {   
    private String cpf;
}
@Stateless
public class PessoaFisicaDAO {
    @TransactionAttribute(TransactionAttributeType.MANDATORY)
    public void incluirPessoa(Pessoa pessoa) {
        em.persist(pessoa);
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="teste">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/testeDS</jta-data-source>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
        <!-- <property name="hibernate.hbm2ddl.auto" value="update" /> -->
        <!-- <property name="hibernate.show_sql" value="true" /> -->
        <!-- <property name="hibernate.format_sql" value="true" /> -->
        <!-- <property name="hibernate.generate_statistics" value="true" /> -->
        <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
    </properties>
</persistence-unit>

08:17:24,371 INFO [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (default task-10) HHH000397: Using ASTQueryTranslatorFactory
08:17:50,974 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-11) SQL Error: 0, SQLState: 42703
08:17:50,976 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-11) ERROR: column "tipo" of relation "tb_pessoa" does not exist
Posição: 52

Thank you.

    
asked by anonymous 21.01.2017 / 14:55

1 answer

0

As indicated by the error itself, there is no column named tipo in the tb_pessoa table. Make sure they exist in your database, since they are not being created by Hibernate because the hibernate.hbm2ddl.auto property is commented out.

If they exist in the database, another possibility is the case difference between the name of that column / table in the database and the name being used for the query, since PostgreSQL changes to lowercase all the names that are not enclosed in quotation marks. You can try to change the name of your columns and tables to lowercase, both in the database and in their entities.

Another possibility is to enable the Hibernate hibernate.globally_quoted_identifiers property so that the case of the tables / columns is maintained as defined in their classes. If you do this, be sure to remove the comment mark from the hibernate.hbm2ddl.auto property for Hibernate to update your tables.

<property name="hibernate.globally_quoted_identifiers" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update" />

One last note, class org.hibernate.dialect.PostgreSQLDialect is marked obsolete. If your PostgreSQL version is equal to or greater than 8.2, change your Dialect to its version:

org.hibernate.dialect.PostgreSQL82Dialect
org.hibernate.dialect.PostgreSQL9Dialect
org.hibernate.dialect.PostgreSQL91Dialect
org.hibernate.dialect.PostgreSQL92Dialect
org.hibernate.dialect.PostgreSQL93Dialect
org.hibernate.dialect.PostgreSQL94Dialect
org.hibernate.dialect.PostgreSQL95Dialect
    
21.01.2017 / 17:22