简体   繁体   English

org.postgresql.util.PSQLException:错误:列 systementi0_.id 不存在 - Hibernate、PostgreSql

[英]org.postgresql.util.PSQLException: Error: column systementi0_.id does not exist - Hibernate, PostgreSql

I'm getting error "column "systementi0_.Id does not exist". I'm using PostgreSql and Hibernate. There is code of my entity:我收到错误“列“systementi0_.Id 不存在”。我正在使用 PostgreSql 和 Hibernate。我的实体有代码:

@Entity
@Table(name = "system_table", schema = "blue_schema")
public class SystemEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "Id", unique = true)
    private int id;

    @Column(name = "name")
    private String name;

    @Column(name = "sys_description")
    private String systemDescription;

    @Column(name = "tech_description")
    private String technologyDescritpion;

    @Column(name = "owner_name")
    private String owner;

    public SystemEntity() {
        // TODO Auto-generated constructor stub
    }

    public SystemEntity(int id, String name, String systemDescription, String technologyDescritpion, String owner) {
        super();
        this.id = id;
        this.name = name;
        this.systemDescription = systemDescription;
        this.technologyDescritpion = technologyDescritpion;
        this.owner = owner;
    }

    public SystemEntity(String name, String systemDescription, String technologyDescritpion, String owner) {
        super();
        this.name = name;
        this.systemDescription = systemDescription;
        this.technologyDescritpion = technologyDescritpion;
        this.owner = owner;
    }

At the beggining I'm trying to get every data from this table from DB.在开始时,我试图从数据库中获取该表中的所有数据。

    @Override
    public List<SystemEntity> getAllSystems() {

        Session currentSession = sessionFactory.getCurrentSession();

        Query<SystemEntity> theQuery = currentSession.createQuery("from SystemEntity", SystemEntity.class);

        List<SystemEntity> listOfSystems = theQuery.getResultList();

        return listOfSystems;
    }

That's my database types and output: Table output那是我的数据库类型和 output:表 output

Table types表类型

My schema name is clarified in @Table annotation, but still getting error:我的模式名称在 @Table 注释中得到了澄清,但仍然出现错误:

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/ContractManager] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
org.postgresql.util.PSQLException: Error: columnsystementi0_.id does not exist.

I saw similar post like mine but solution was simple, just add schema name in @Table.我看到了类似的帖子,但解决方案很简单,只需在 @Table 中添加模式名称。

maybe you should use the Integer , data type instead of int , and you should try to use the table name directly.也许你应该使用Integer ,数据类型而不是int ,你应该尝试直接使用表名。 system_table

It's a common mistake.这是一个常见的错误。 The first recommendation: don't use uppercase in the name of all database entities: schemas, tables or columns.第一个建议:不要在所有数据库实体的名称中使用大写:模式、表或列。 Your id column name has " Id ".您的id列名称具有“ Id ”。 Try " id ".试试“ id ”。 The second: I recommend you in postresql use sequence generator:第二:我推荐你在postresql中使用序列生成器:

@Entity
@Table(name = "system_table", schema = "blue_schema")
@SequenceGenerator(schema = "blue_schema", name = "system_table_seq", allocationSize = 1, sequenceName = "system_table_seq")
public class SystemEntity {

    // other code below 
    // ... 

}

And the last recommendation: don't use primitive types in JPA entities.最后一个建议:不要在 JPA 实体中使用原始类型。 Try to:尝试:

@Entity
@Table(name = "system_table", schema = "blue_schema")
@SequenceGenerator(schema = "blue_schema", name = "system_table_seq", allocationSize = 1, sequenceName = "system_table_seq")
public class SystemEntity {

    @Id
    @GeneratedValue(generator = "system_table_seq", strategy = GenerationType.SEQUENCE)
    private Integer id;

    // other code below 
    // ... 

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.postgresql.util.PSQLException:错误:列 user0_.id 不存在 - Hibernate - org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist - Hibernate org.postgresql.util.PSQLException:错误:列“id”不存在 - Java Web 服务 - org.postgresql.util.PSQLException: ERROR: column "id" does not exist - Java Web Service org.postgresql.util.PSQLException:错误:关系“用户”不存在 - SpringBoot,Hibernate,Postgresql - org.postgresql.util.PSQLException: ERROR: relation "users" does not exist - SpringBoot, Hibernate, Postgresql org.postgresql.util.PSQLException:错误:关系“序列”不存在 - org.postgresql.util.PSQLException: ERROR: relation “sequence” does not exist org.postgresql.util.PSQLException:错误:关系“产品”不存在 - org.postgresql.util.PSQLException: ERROR: relation "products" does not exist 错误:org.postgresql.util.PSQLException:错误:列 userinfo0_.dtype 不存在 - ERROR:org.postgresql.util.PSQLException:ERROR: column userinfo0_.dtype does not exist org.postgresql.util.PSQLException:错误:列 column0_.pk 不存在 Position:8 - org.postgresql.util.PSQLException: ERROR: column column0_.pk does not exist Position: 8 引起:org.postgresql.util.PSQLException:错误:列 performanc3_.app_user_internal_user_id 不存在 - Caused by: org.postgresql.util.PSQLException: ERROR: column performanc3_.app_user_internal_user_id does not exist org.postgresql.util.PSQLException:错误:关系“clienti_id_seq”不存在 - org.postgresql.util.PSQLException: ERROR: the relation“clienti_id_seq” does not exist org.postgresql.util.PSQLException:致命:数据库“ postgres&gt;”不存在 - org.postgresql.util.PSQLException: FATAL: database “postgres>” does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM