PDA

View Full Version : LAZY AND PROPAGATION_REQUIRED



fmourioux
Aug 27th, 2004, 12:39 PM
Hi

I using an hibernate filter for the view, no problem.

But I don't understand why when i do in a quartz job :

1. managerCompagny.saveCompany(company);
2. company.getUsers()

I have a "lazy exception" for the second line that is just after the first one.

My "managerCompagny.saveCompany" has PROPAGATION_REQUIRED, so it use a session is exist (if not it creates one) but why close the session after ?

Excuse me for this stupid question but i want to understand.

Fabien.

Colin Sampaleanu
Aug 28th, 2004, 08:15 PM
The OpenSessionInView filter is not going to help you for the quartz job, since that's going to happen in a different thread.

You need to ensure that you encompass both operations 1 and 2 in one transaction. The Session will remain open for the duration of the transaction. One way to do this is by wrapping these 2 operations in one method that is itself transactional.

fmourioux
Aug 29th, 2004, 01:41 PM
Ok Collin, i understand.

In fact, i replace company.getUsers() by managerCompagny.getUser(idCompagny), so in my manager with PROPAGATION_REQUIRED.

Thanks,

Fabien