您好我的春季启动postgresql应用程序,当我使用DAO检索所有记录时,它显示列不存在。
错误
WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42703
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column merchantit0_.id does not exist
Position: 8
ERROR: org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/customerplus].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/customerplus] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
org.postgresql.util.PSQLException: ERROR: column merchantit0_.id does not exist
Position: 8
实体域
@Entity
@Table(name = "merchant_item_category")
public class MerchantItemCategory{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false, length = 11)
private long id;
@ManyToOne
@JoinColumn(name = "merchant_id", nullable = false)
private Merchant merchant;
// getters and setters
}
DAO
public List<MerchantItemCategory> getAllMerchantItemCategoryByMerchantId(long id) {
Session session=getSession();
List<MerchantItemCategory>itemCategories=session.createQuery("from MerchantItemCategory where merchant.id=:merchantId and isDelete='0' order by categoryName asc")
.setParameter("merchantId", id)
.list();
return itemCategories;
}
我刚刚检查了每个对象并且它是正确的,但是这个错误是如何发生的......!
答案 0 :(得分:2)
此错误的一个潜在原因是您尚未定义hibernate“default schema”属性。
我通过在app.properties:
下面添加以下行修复了此问题spring.jpa.properties.hibernate.default_schema=${your-default-schema-name}