简体   繁体   中英

Column does not exist in spring boot Postgres app

Hi in my spring boot postgresql application, when i retrieve all record using DAO it show column does not exists.

ERROR

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 Domain

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

I just checked every object and it is correct, But how this error occurring..!

A potential cause of this error is when you haven't defined the hibernate "default schema" property.

I fixed this issue by adding line below to my application.properties:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM