簡體   English   中英

Spring Boot Postgres應用程序中不存在該列

[英]Column does not exist in spring boot Postgres app

嗨,在我的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
}

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

我只是檢查了每個對象,它是正確的,但是該錯誤如何發生..!

導致此錯誤的潛在原因是尚未定義休眠的“默認架構”屬性。

我通過在我的application.properties中添加以下行來解決此問題:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM