【问题标题】:Column does not exist in spring boot Postgres appspring boot Postgres应用程序中不存在列
【发布时间】: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


【解决方案1】:

此错误的一个潜在原因是您尚未定义休眠“默认架构”属性。

我通过在 application.properties 中添加以下行来解决此问题:

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

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 2018-12-12
    • 2019-11-20
    • 2019-11-16
    • 2020-05-22
    相关资源
    最近更新 更多