如何在可嵌入对象的集合中两次映射相同的列?

时间:2016-05-18 00:06:42

标签: hibernate hibernate-mapping

我希望多次映射同一列。为此,第二个映射是只读的。在大多数情况下,这种方法有效 但是,在这种情况下,我得到以下错误:

 Repeated column in mapping for collection: Order.content column: item_id

请你帮我理解一下,我的代码是什么样的:

 @Entity
 class Order {
    ...


    @OrderColumn(name = "idx")
    @JoinColumn(name = "order_id")
    @ElementCollection(fetch = LAZY)
    @CollectionTable(name = "order_content", schema = "orders")
    private List<OrderContent> content;
  } 

  @Embeddable
  class OrderContent {
      @JoinColumn(name = "item_id")
      @ManyToOne(fetch = LAZY, targetEntity = Item.class)
      private Long itemId;

      @JsonIgnore
      @ManyToOne(fetch = LAZY, targetEntity = Item.class)
      @JoinColumn(name = "item_id", insertable = false, updatable = false)
      private Item item;
  }

谢谢。

0 个答案:

没有答案