首页 > 解决方案 > 为什么我的应用程序总是连接到“公共”模式?

问题描述

我正在尝试使用 springboot+jpa 连接到 postgres 数据库

postgres 在数据库中有两个模式

public
ratings

评级模式具有表 food_ratings

即使我尝试了以下被广泛建议的方法,默认模式总是被选择为公共而不是评级模式

-> 在应用程序属性中显式设置默认模式

spring.jpa.properties.hibernate.default_schema=ratings

->在实体中明确将模式设置为评级

@Getter
@Setter
@Entity
@Table(name = "food_ratings", schema = "ratings")
public class FoodRatings implements Serializable {
    @Id
    @Column(name = "id")
    private String id;

   @Column(name="description")
    String description;

}

我最终得到错误

org.postgresql.util.PSQLException: ERROR: relation "food_ratings" does not exist

注意:我在代码和数据库中都使用小写的模式名和表名。我在这里还缺少什么其他选择?

标签: javaspringpostgresqlspring-bootjpa

解决方案


问题出在 postgres 驱动程序版本上。我使用的是 9.x 版本。

将其升级到 42.0.0 使其工作。


推荐阅读