org.h2.jdbc.JdbcSQLException:Column" column_name"未找到

时间:2018-02-20 20:43:20

标签: java hibernate jpa jdbc spring-data-jpa

我有3个实体:订单,产品和消费者:

@Entity
@Table(name = "PRODUCT")
public class Brick {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    Order order;
    // ... getters & setters
}

@Entity
@Table(name = "CONSUMER")
public class Consumer{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
}

@Entity
@Table(name = "ORDER")
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToMany(mappedBy = "order")
    private List<Product> products;

    @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
    @MapsId
    private Consumer consumer;
}

这些表类似于波纹管表示,包含括号中的属性:
消费者(ID)

产品(ID)

订单(id,product_id,consumer_id),order_id引用Product(id),consumer_id引用Consumer(id)

我正在发送一个帖子请求:

{
  "id": 1,
  "products" : [
    {"id" : 1},
    {"id" : 2}
   ],
   "consumer":1
}

在尝试保存订单时给出了以下错误:

org.h2.jdbc.JdbcSQLException: Column "PRODUCT0_.ORDER_CONSUMER_ID" not found; SQL statement:
select product0_.id as id1_0_0_, product0_.order_consumer_id as order_cu2_0_0_ from product product0_ where product0_.id=? [42122-196]

我的存储库扩展了CrudRepository,我正在使用repository.save(dto)来保存数据。

我不知道它正在寻找那个专栏。 你可以指导我解决这个问题吗?

0 个答案:

没有答案