我在带有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不支持别名吗?
这是一个PgAdmin窗口,其中有一个有效的选择:
查询是相同的,除了#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"/>