JPA 和 eclipselink - 重写 FetchType.Eager
我有一个类,其中一些成员有注释:
@ManyToOne(fetch = FetchType.EAGER)
在我的程序的特定部分中,这些加载了太多数据。不幸的是,我无法更改这些注释,因为这会影响该程序其他部分的性能。 eclipselink 中有没有办法将 1 个特定的 JPQL 查询更改为 LAZY?
换句话说,您可以使用 fetch join 将 LAZY 更改为 EAGER。我希望有一些东西可以将渴望变成懒惰
I have a class where a few members have annotation:
@ManyToOne(fetch = FetchType.EAGER)
In the specific part of my program, these load far too many data. Unfortunately, I can't change these annotations as this will influence performance of other parts of this program. Is there a way in eclipselink to change this to LAZY for 1 specific JPQL query?
To phrase this an other way, you can change LAZY to EAGER by using a fetch join. I'm hoping for something which changes EAGER to LAZY
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是不可能的。我的经验法则是:让一切变得懒惰,如果你想要急切地获取,就使用自定义查询。
您能做的最好的事情就是加载元组(并填充 DTO)而不是加载实体。
It's not possible. My rule of thumb is : make everything LAZY, and use custom queries if you want eager fetching.
The best you can do is to load tuples (and populate DTOs) instead of loading entities.
我知道从 eclipselink 2.3 开始你可以在运行时扩展你的实体,也许检查一下?
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Extensibility
I know that since eclipselink 2.3 you can extend your entities at runtime, maybe check that?
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Extensibility