栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Jersey的JAX-RS在休眠资源类中使用连接表进行多对一

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Jersey的JAX-RS在休眠资源类中使用连接表进行多对一

在多个方面定义联接表,但不要在一侧再次定义它。这将创建映射到同一表的两个单向关联,而不是一个双向关联。

双向关联始终具有所有者侧(您可以在其中指定要使用的连接列或连接表),以及通过使用mapledBy属性可以说是另一侧的反向的反向侧:

public class Activity {    @ManyToOne // owner side: it doesn't have mappedBy, and can decide how the association is mapped: with a join table    @JoinTable(name="category_activity",    joinColumns={@JoinColumn(name="activities_id")},    inverseJoinColumns={@JoinColumn(name="Category_id")})    private Category category;}public class Category {    @oneToMany(mappedBy = "category") // inverse side: it has a mappedBy attribute, and can't decide how the association is mapped, since the other side already decided it.    @Fetch(FetchMode.JOIN)    @JsonIgnore    private Collection<Activity> activities;}

编辑:

此外,您的查询应仅通过添加select子句来选择活动,而不是查询所连接的所有实体:

select a from Activity as a where a.category.id= :categoryId order by a.key


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/568887.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号