Hibernate opening/closing session, the correct approach for DAO

拥有回忆 提交于 2019-12-04 12:08:40

Good approach is to add close method to your DAO(AbstractDao) and call it the end of your "unit of work".

And, please, no static references to session, session is not thread safe


Here is a brilliant explanation with sample: Link

You can hold a static Session member in HibernateUtil. Lazy initialized. An close the session whenever you want, but until it isn't closed, you'll keep using it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!