在我的Spring PoostPostgreSQL应用程序中,当我使用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
}


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;
    }

我刚刚检查了每个对象,结果都是正确的,但是这个错误是怎么发生的。。!

最佳答案

此错误的一个潜在原因是尚未定义hibernate“默认架构”属性。
我通过在application.properties中添加以下行修复了此问题:

spring.jpa.properties.hibernate.default_schema=${your-default-schema-name}

10-08 04:52