viq
viq

Reputation: 417

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!

Upvotes: 1

Views: 822

Answers (1)

urbiwanus
urbiwanus

Reputation: 723

  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.

Upvotes: 2

Related Questions