无法提取ResultSet,列不存在

时间:2015-05-14 12:36:40

标签: java spring hibernate postgresql

我有像

这样的实体
  @Entity
    @Table(name = "ebooking")
    public class EBooking {

        @Id
        @Column(name = "bookId")
        private String bookId;

我实现了存储库llike

public interface EBookingRepository extends JpaRepository<EBooking, String>, JpaSpecificationExecutor<EBooking> {

    @Query("select book from EBooking book where book.bookId = :id")
    EBooking getByBookId(@Param("id") String id);
}

当我尝试运行此方法时,我有异常:

org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

org.postgresql.util.PSQLException: ERROR: column ebooking0_.book_id does not exist
  Position: 8

为什么ebooking0_.book_id?只有ebooking表。

谢谢!

1 个答案:

答案 0 :(得分:1)

ebooking0_是Hibernate生成的ebooking表的别名。如果打开SQL日志记录,可以检查它。

错误确实表明您在表book_id中没有列ebooking