Hibernate can run as a stand-alone library integrated with Java.
But with Spring Framework, we can now integrate Hibernate + Spring + Java. The basic concept is that we can use the Spring Hibernate Library which already has Hibernate DAO functionalities ( DAO = Data Access Object )
In this case, Spring will do all the Hibernate session handling and database connection. In the Java Hibernate codes, we just need to configure the Java class that is the mapping of the database table and the xml database mapping must also be configured.
( I will add more to this topic since I noticed this gets hits )
In my own experience without Spring, there’s a lot of Java-Hibernate code to do, from database connection including commits and transactions. In the case where you will be using Spring, most of the repeated database transaction code can already be used under the Spring-Hibernate libraries.
Below is the table taken from the Official Spring documentation on how some parts of JDBC functions are already done in Spring ( Note that this is JDBC only, although Hibernate will use Spring JDBC functions ) :
|Define connection parameters.||X|
|Open the connection.||X|
|Specify the SQL statement.||X|
|Declare parameters and provide parameter values||X|
|Prepare and execute the statement.||X|
|Set up the loop to iterate through the results (if any).||X|
|Do the work for each iteration.||X|
|Process any exception.||X|
|Close the connection, statement and resultset.||X|
More detailed explanations in the links below: