简体   繁体   中英

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. 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:

  1. Use the bean management transactions, and load the fields in that transactions (it's difficult because a lot of legacy code i have)

  2. Use the eager initialization in entities.

Do you have any other ideas?

Thank you!

  1. Not a good idea

2 .Eager loading is not a good idea too, because the risk to load the whole database into memory is really high.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM