【问题标题】:SQL error or missing database / OneToMany SQLIte-Spring BootSQL 错误或缺少数据库/OneToMany SQLIt-Spring Boot
【发布时间】:2019-07-15 03:00:26
【问题描述】:

我对 oneToMany 的关系有疑问。我在 SQLite DB 中创建了表,这是我的表:

我的类别模型:

@Entity
@Table(name = "Category")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class CategoryModel {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    private String category_name;
    private String category_description;
    private String image_path;

    @JsonIgnore
    @OneToMany( mappedBy = "category")
    private Set<ProductModel> category;

我的产品类别:

@Entity
@Table(name = "Product_Category")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class ProductModel {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long product_id;
    private Long category_id;

    private String name;
    private String description;
    private int numberOfProduct;
    private String image;
    private int price;

    @ManyToOne
    @JoinColumn(name = "country_id", nullable = false)
    private CategoryModel category;

我可以很好地从Category 表中获取数据,但是当我从 Product_Category 表中调用数据时出现错误:

SQL error or missing database (no such column: productmod0_.country_id)

【问题讨论】:

    标签: spring-boot sqlite spring-data-jpa


    【解决方案1】:

    country_id 在您的表中的任何位置都不存在。

    你想要的是:@JoinColumn(name = "category_id", nullable = false)

    【讨论】:

    • 现在我有这个错误:[SQLITE_ERROR] SQL error or missing database (no such column: productmod0_.id)
    • @Column(name = "id") 在 JPA 中,但 product_id 在数据库中。这一切不是很明显吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2018-04-10
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    相关资源
    最近更新 更多