Spring Hibernate Integration Example

Spring Hibernate Integration Example:
Here is a code for Spring and Hibernate integration in Netbeans 8.0.2.

Create Project:
File–>New Project –>Java –>Web Application
Give a name to the application and click Next–>Next–>
Choose Spring and Hibernate in Frameworks and choose the database for Hibernate. and click Finish

Create 2 packages inside Source Package and name them as,
1) Dao
2) pojo

Inside pojo, create 2 java class
1) Student.java
2) insert.java
3) Right click pojo –>New–>HibernateUtil.java and click Finish

Inside Dao, Create a java class
1) StudentDao.java

student table (MySQL)

Right Click Source packages, New–> Hibernate Reverse Engineering –> select the table –> Add –>Finish

Right click pojo –>New–>Hibernate Mapping files and Pojo’s from Database–>Finish

Directory Structure:
springhiber

Student.java

StudentDao.java

applicationContext.xml

hibernate.cfg.xml

insert.java

Output:
(insert some sample values in your student table – I have inserted a name with victor 3 times with different id’s)

outpu1

 

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *