【发布时间】:2019-10-21 15:43:16
【问题描述】:
我收到错误“列”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;
}
一开始我试图从数据库中获取该表中的所有数据。
@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;
}
这是我的数据库类型和输出: Table output
@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.
我看到了类似的帖子,但解决方案很简单,只需在 @Table 中添加架构名称。
【问题讨论】:
-
尝试将此
private int id;更改为Integer或Long -
还是同样的错误
-
尝试在列名中使用“id”而不是“Id”。 Postgresql 列名通常是小写的,如果你没有使用这样的引号创建列:create column "Id" integer;如果它不起作用,也许你应该像这样在映射中明确引用列 nmae:@Column(name = "\"Id\"", unique = true)
标签: java spring postgresql hibernate