[英]JPA and EJB lazy initialization fields
I use jpa (eclipselink) + ejb(3) in my project, when i switch off transactions on ejb method there is a problem with a lazy loading. 我在项目中使用jpa(eclipselink)+ ejb(3),当我关闭ejb方法上的事务时,延迟加载存在问题。 If i try to Eager loading that's ok, but a it have more time to wait.
如果我尝试快速加载是可以的,但是它有更多时间等待。 How do you solve problems like that?
您如何解决这样的问题? I think there are 2 methods:
我认为有2种方法:
Use the bean management transactions, and load the fields in that transactions (it's difficult because a lot of legacy code i have) 使用Bean管理事务,并在该事务中加载字段(这很困难,因为我拥有很多旧代码)
Use the eager initialization in entities. 在实体中使用急切的初始化。
Do you have any other ideas? 你还有其他建议吗?
Thank you! 谢谢!
2 .Eager loading is not a good idea too, because the risk to load the whole database into memory is really high. 2。提前加载也不是一个好主意,因为将整个数据库加载到内存的风险确实很高。
If its possible try to create (named)queries with fetch joins ( see http://www.kumaranuj.com/2013/07/jpa-2-fetch-joins-and-whether-we-should.html ) which only loads data you really need for further processing. 如果可能的话,尝试使用获取联接创建(命名)查询(请参阅http://www.kumaranuj.com/2013/07/jpa-2-fetch-joins-and-whether-we-should.html ),该查询仅会加载您确实需要进一步处理的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.