【问题标题】:how to use mapBy when collection is an HashMap and not a simple List?当集合是 HashMap 而不是简单的 List 时如何使用 mapBy?
【发布时间】:2015-03-17 15:45:26
【问题描述】:

我有以下无法创建的实体:

 @OneToMany( fetch = FetchType.LAZY, orphanRemoval=true, mappedBy="itemA" )
 @Cascade( { CascadeType.ALL } ) 
 @MapKey( name="id.customKey" )
 private Map<String, ItemB> bMap;

它给了我一个:

Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property

ManyToOne 类属性如下:

@ManyToOne( optional=false )
@NotFound( action=NotFoundAction.EXCEPTION )
@JoinColumn( name="ID_ITEM_B", nullable=false, updatable=true, insertable=true  )
private ItemA itemA;

这段代码似乎在 ItemB 列表中运行良好,但当我使用 Map 时出现问题......怎么会?

【问题讨论】:

    标签: java hibernate


    【解决方案1】:

    使用 Map 时,只添加@MapKey( name="id.customKey" ),不要使用mappedBy。 在这里查看答案:How do you map a "Map" in hibernate using annotations?

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多