Spring annotation based configuration change -
i have spring mvc (3.1) web app using hibernate working correctly - today, have tried move configuration on annotation based config (only using xml security stuff isnt yet supported spring in code config).
after tuning got app starting no errors , home page loads correctly - seeing different behaviour hibernate sessions - namely, getting following error when loading page touches hibernate entities:
org.hibernate.lazyinitializationexception: failed lazily initialize collection of role: com.tmm.web.domain.profile.connections, no session or session closed
this happening in following scenario:
- a request hits
@controller
, loads userprofile
object - in same method call (so not talking detached entities etc here) tries call
profile.getconnections()
profile.connections not explicitly state fetchtype, should default eager load (is understanding?), either way,
getconnections()
call directly after loading ofprofile
- have thought if being loaded lazily, go db , load connections on demand.//@controller code account vieweduser = accountservice.loadaccountbyusername(username); model.put("vieweduserconnections", vieweduser.getuserprofile().getconnections());
//profile entity @onetomany(mappedby = "user", cascade = cascadetype.all) private list connections = new arraylist();
now, know lazy loading etc, it's not question - mentioned hibernate stuff working correctly - question is, spring configuration might affect behaviour?
i can post before , after xml vs annotation config, hoping can point me in direction of config might have missed in switching.
your assumptions wrong:
in same method call (so not talking detached entities etc here)
the method method of controller. in typical spring applications, controllers not transactional, services are. so, unless configured "open session in view" filter or interceptor, session closed when transactional service method returns, , controller uses detached entities
profile.connections not explicitly state fetchtype, should default eager load
no. xxxtomany associations lazy default.
if same code worked before transition, guess had open session in view filter or interceptor, , forgot when migrating annotations.
Comments
Post a Comment