hibernate:与未映射实体的关联
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;
}
由于布尔类型不是映射实体,因此它给出错误“针对未映射的类”。
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".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这种情况,您需要集合映射(JPA 2.0 注释中的
@ElementCollection
或 Hibernate 注释中的@CollectionOfElements
)而不是关系映射(@...To.. .
)。例如,使用 JPA 2.0 注释:
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: