hibernate:与未映射的实体的关联

时间:2010-12-30 09:48:34

标签: java mysql hibernate associations ternary

     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;
    }

由于布尔类型不是映射实体,因此它给出错误“定位未映射的类”。

1 个答案:

答案 0 :(得分:1)

对于这种情况,您需要集合映射(JPA 2.0注释中的@ElementCollection或Hibernate注释中的@CollectionOfElements)而不是关系映射(@...To...)。

例如,使用JPA 2.0注释:

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