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;
}
由于布尔类型不是映射实体,因此它给出错误“定位未映射的类”。
答案 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;