开发者

hibernate: association with unmapped entity

     table : map__company__branches (company_id int, 开发者_运维技巧branch_id int, is_primary_branch tinyint(1))

    public class company
    {
     @ManyToMany(fetch = FetchType.LAZY)
     @JoinTable(name = "map__company__branches", joinColumns = { @JoinColumn(name = "company_id") })
     @MapKeyManyToMany(joinColumns = { @JoinColumn(name = "branch_id") })
         @column(name="is_primary_branch")
         Map<Branch, Boolean> branchMap;
    }

Since Boolean type is not mapped entity so its giving error "targeting an unmapped class".


For this case you need collection mapping (@ElementCollection in JPA 2.0 annotations or @CollectionOfElements in Hibernate annotations) rather than relationship mapping (@...To...).

For example, with JPA 2.0 annotations:

@ElementCollection
@CollectionTable(name = "map__company__branches",
    joinColumns = @JoinColumn(name = "company_id"))
@MapKeyJoinColumn(name = "branch_id")
@Column(name = "is_primary_branch")
Map<Branch, Boolean> branchMap; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜