使用Hibernate别名的Postgres查询无法运行

时间:2017-11-15 18:28:45

标签: postgresql hibernate jpa

我在带有PostgreSQL 10数据库的Java应用程序中使用Hibernate / JPA。

以下JPA翻译的查询有错误:

select
    question0_.ID as id1_0_,
    question0_.LABEL as label2_0_ 
from
    public."QUESTIONS_T" question0_ 
where
    question0_.id=1

ERROR

column question0_.id does not exist

但是所有内容在语法上都是正确的。 Postgres不支持别名吗?

enter image description here

这是一个PgAdmin窗口,其中有一个有效的选择:

enter image description here

查询是相同的,除了#1使用别名。作为参考,我的实体模型对象:

@Entity
@Table(name = "public.\"QUESTIONS_T\"") 
public class Question {

    @Id
    Integer id; 

    String label;

    @Column(name="ID")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name="LABEL")
    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }   

}

Hibernate persistence.xml:

        <property name="hibernate.archive.autodetection" value="class"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hbm2ddl.auto" value="update"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        <property name="hibernate.connection.url"
                  value="jdbc:postgresql://localhost:5432/postgres"/>
        <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>

0 个答案:

没有答案