How Hibernate is integrated in Spring

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 ) :

http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/jdbc.html#jdbc-embedded-database-support

Action Spring You
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
Handle transactions. X
Close the connection, statement and resultset. X

More detailed explanations in the links below:

http://howtodoinjava.com/2013/03/21/spring-3-and-hibernate-integration-tutorial-with-example/

http://www.studytrails.com/frameworks/spring/spring-hibernate-dao-support.jsp

http://www.javatpoint.com/hibernate-and-spring-integration

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s