Hi,
first: i don't and don't want to use OpenSessionInView (OSIV). This would be the easiest solution to my problem. But for several reasons i don't want to use it (and should be discussed elsewhere)
I have a service layer using Spring 2.0 transaction advice (<aop:advisor> and <tx:advice>).
Imagine a service layer with two methods:
My Controller needs both of them:Code:getMostRecentElement() getElements()
ServiceLayer has a repostiory injected which extends HibernateDaoSupport.Code:Object formBackingObject (...) { return service.getMostRecentElement(); } Map referenceData(...) { return service.getElements() }
the calls to
- getMostRecentElement()
- getElements()
both start a transaction and grab a new session. Therefore without a second level cache hibernate will query the db two times to get all elements as getMostRecentElement() iterates over all elements.
I just want to stop hibernate from querying the dB twice. So i want to keep my session open while handleRequest is executed. I don't want to use 2nd level cache for it as these elements will only be of use in this request. The easiest thing would be to keep the session open and use hibernates 1st level cache.
I could make my handleRequest transactional, but i don't think that transactional Controllers are a good thing.
As i didn't found anything in forum or web about my problem i rather think it is not a good approach. Maybe i misunderstood something. if so, please tell me why, if not please tell me how to keep the session open.
please, enlighten me. Your help is very appreciated.
kind regards
Janning


Reply With Quote
