【发布时间】:2016-05-01 10:42:02
【问题描述】:
嗨,在我的 spring boot 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;
}
我刚刚检查了每个对象,它是正确的,但是这个错误是怎么发生的..!
【问题讨论】:
-
如错误所述:表“merchant_item_category”没有列“id”。创建它或将“hibernate.hbm2ddl.auto”属性设置为“update”。
标签: java spring postgresql spring-mvc