JPA and eclipselink - Overriding FetchType.Eager

守給你的承諾、 提交于 2019-12-23 16:15:38

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/7027707/jpa-and-eclipselink-overriding-fetchtype-eager

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!