terrestris / shogun-legacy

⛔️ DEPRECATED, please use https://github.com/terrestris/shogun-core
Other
16 stars 16 forks source link

Avoiding LazyInitializationException when executing getUsers() or getModules() #49

Closed chrismayer closed 10 years ago

chrismayer commented 10 years ago

To prevent a LazyInitializationException when requesting the app-context with a logged in user the FetchMode of the Group-User- and the Group-Module-relationship is changed to EAGER.

marcjansen commented 10 years ago

I don't have time right now to test this (and its effects) in our applications built atop SHOGun, but pointed @buehner towards this PR. Expect feedback here soon, @chrismayer.

buehner commented 10 years ago

Hi, i would not suggest to merge this commit as it seems to lead to heavy performance problems once you have a large number of associated entities (like a few hundred users in one group).

I tried one of our applications with the proposed EAGER config and it was not possible to use it anymore when groups are requested at some point.

Maybe you can try one of the following options:

  1. Is it possible for you to call the getUsers() or getModules() methods within the sql-session/transaction (which should not lead to the LazyInitializationException)?
  2. You could try to make use of the initializeDeep-flag, which is available for some of the DatabaseDao-methods (or explicitly call one of the initializeDeep-methods).
chrismayer commented 10 years ago

Okay, sounds reasonable that performance will be a problem and in case of having a large number of entities. I will dig into that as soon I find a time slot.

I changed the title of this PR according to the new situation.

chrismayer commented 10 years ago

As discussed I provided another solution: Now the modules of the user object are fetched programatically within the same transaction while requesting the app-context, so the FetchType can remain LAZY within the model class. @buehner and @marcjansen would you please test again in your setup? TIA!

weskamm commented 10 years ago

works for me, tested in big project setup. thanks for this, will merge