如何对 Entity-Bean @OneToMany 关系应用默认限制
我有两个实体模型:客户和订单。每个客户可能有数千个订单。我在这两个实体之间有 OneToMany 和 ManyToOne 关系。
如何将此关系的列表限制为仅前 10 个订单?
是否可以将“WHERE”条件作为 @OneToMany 的属性应用?
就像:
@OneToMany("Where Order.orderNo > 100")
我的问题是当实体管理器创建的对象时,所有订单都在内存中创建。 延迟加载无法解决我的考虑,因为我需要在默认构建中获取前10个订单。
I have two entity models, Customer and Order. Each customer could have thousands of orders. I have a OneToMany and ManyToOne relationship between these two entities.
How do I restrict this relationship's list to only top 10 orders?
Is it possible to apply 'WHERE' condition as an attribute on @OneToMany or not?
Like:
@OneToMany("Where Order.orderNo > 100")
My problem is when the object created by Entity Manager all Orders are created in memory.
Lazy loading can not solve my consideration, because I need to get top 10 orders in default construction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不适用于标准 JPA。但一些提供商对此有扩展。例如,Hibernate 确实有一个
@Where
注解:参考资料
Not with standard JPA. But some providers have extensions for this. For example, Hibernate does have a
@Where
annotation:References
JPA 不支持这一点。但在 EclipseLink 中,您可以使用表达式来过滤关系。
看,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria
JPA does not support this. But in EclipseLink you can use an Expression to filter a relationship.
See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria