open-session-in-view

Hibernate Open Session in View: Transaction per Request?

雨燕双飞 提交于 2019-11-28 20:37:07
问题 I'm using Hibernate with Spring on Tomcat. I've been reading and re-reading the oft pointed to JBoss wiki page on the topic, and that has been helpful. But it leaves me with some questions. The idea of starting a transaction for every request troubles me. I guess I could limit the filter to certain controllers -- maybe put all my controllers that need a transaction under a pseudo "tx" path or something. But isn't it a bad idea to use transactions if you don't know if you're going to need one?

Why is Hibernate Open Session in View considered a bad practice?

十年热恋 提交于 2019-11-25 23:45:46
问题 And what kind of alternative strategies do you use for avoiding LazyLoadExceptions? I do understand that open session in view has issues with: Layered applications running in different jvm\'s Transactions are committed only at the end, and most probably you would like the results before. But, if you know that your application is running on a single vm, why not ease your pain by using an open session in view strategy? 回答1: Because sending possibly uninitialised Proxies, especially collections,