Search code examples
javahibernatesessionarchitecturedao

How to wrap and hide the Hibernate Session


Is there a way to wrap Hibernate's Session with my own class? My purpose is to limit Hibernate within data management layer. My business layer will do session management for opening a new session and close a finished session. But I hope there is no Hibernate import exist in the business layer. Is this possible?


Solution

  • You can use an intermediate DAO layer to hide the Hibernate Session details from your business logic.

    You can use Spring Transaction support for session management and Spring Data for the simplest possible DAO layer implementation.

    There's no need to reinvent the wheel.