Spring Core

Spring Hibernate Integration with Example

<p>In this Spring Hibernate Integration with Example tutorial we will see that how to configure the Hibernate with Spring framework with using one example&period;<&sol;p>&NewLine;<h2>Spring Hibernate Integration<&sol;h2>&NewLine;<div dir&equals;"ltr" style&equals;"text-align&colon; justify&semi;">&NewLine;<div dir&equals;"ltr" style&equals;"text-align&colon; justify&semi;">&NewLine;<div dir&equals;"ltr" style&equals;"text-align&colon; justify&semi;"><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;hibernate-3-on-baby-steps&sol;">Hibernate<&sol;a><&sol;b> is a powerful technology for persisting data in any kind of Application&period; <b>Spring<&sol;b>&comma; on the other hand is a <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;dependency-injection-in-spring&sol;">dependency injection<&sol;a><&sol;b> framework that supports <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-ioc-container&sol;">IOC<&sol;a><&sol;b>&period; The beauty of Spring is that it can integrates well with most of the prevailing popular technologies&period;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img title&equals;"Spring Hibernate Integration with Example" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2012&sol;12&sol;Spring-Hibernate-Integration-Example&period;png" border&equals;"0" &sol;><&sol;div>&NewLine;<p>If you are new to <b><i>Spring and Hibernate<&sol;i><&sol;b> frameworks&comma; please read the introduction articles on <b><i>Spring and Hibernate<&sol;i><&sol;b> before start reading this article&period; <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;">DineshonJava<&sol;a><&sol;b> has explained in <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-tutorial&sol;">Introduction to Spring Framework<&sol;a>&period; This article will help you to understand the fundamentals of the <b><i>Spring framework<&sol;i><&sol;b>&period; In another article <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;hibernate-3-on-baby-steps&sol;">Introduction to Hibernate<&sol;a><&sol;b> published on 27&sol;03&sol;2012 by <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;">DineshonJava<&sol;a><&sol;b> explains what is <b><i>ORM framework<&sol;i><&sol;b> and how to start writing the simple <b><i>hibernate<&sol;i><&sol;b> application&period;<&sol;p>&NewLine;<div style&equals;"background-color&colon; &num;f2f9fc&semi; border&colon; 1px solid &num;c9e6f2&semi; border-radius&colon; 3px&semi; padding&colon; 16px&semi; line-height&colon; 1&period;45&semi;"><span style&equals;"color&colon; red&semi; font-size&colon; x-large&semi; text-align&colon; center&semi;"><b>Popular Tutorials<&sol;b><&sol;span><&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-tutorial&sol;"><em><strong>Spring Tutorial<&sol;strong> <&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-web-mvc-framework-chapter-38&sol;"><strong><em>Spring MVC Web Tutorial <&sol;em><&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;introduction-to-spring-boot-a-spring-boot-complete-guide&sol;"><strong>Spring Boot Tutorial<&sol;strong> <&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-take-baby-step-to-secure&sol;"><em>Spring Security Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint&sol;"><em>Spring AOP Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;using-spring-jdbc-framework-chapter-32&sol;"><em>Spring JDBC Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-hateoas-hypermedia-driven-restful-web-service&sol;"><em><strong>Spring HATEOAS <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;microservices-with-spring-boot&sol;"><em><strong>Microservices with Spring Boot<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;jax-rs-web-service-tutorial&sol;"><strong><em>REST Webservice<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;core-java-baby-step-to-be-best-java-ian&sol;"><em><strong>Core Java <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;hibernate-3-on-baby-steps&sol;"><em><strong>Hibernate Tutorial<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-batch-process-with-example&sol;"><strong><em>Spring Batch<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;div>&NewLine;<div id&equals;"ads-id" align&equals;"center"><&sol;div>&NewLine;<h2><b>Spring and Hibernate&colon;<&sol;b><&sol;h2>&NewLine;<p>As a pre-requisite&comma; let us understand the need for such integration before we actually get into the integration between these two technologies&period; It is well known that <b>Hibernate<&sol;b> is a powerful <i><b>ORM tool<&sol;b><&sol;i> that lies between Application and Database&period; It enables Application to access data from any database in a platform-independent manner&period; There is no need for the Application to depend on the low-level <b>JDBC<&sol;b> details like managing connection&comma; dealing with statements and result sets&period; All the necessary details for accessing a particular data source is easily configurable in Xml files&period; Another good thing is that Hibernate can be coupled well with both J2SE and J2EE Applications&period;<&sol;p>&NewLine;<p>One of the problem with using <b>Hibernate<&sol;b> is that the client Application that accesses the database using <i><b>Hibernate Framework<&sol;b><&sol;i> has to depend on the <b>Hibernate<&sol;b> APIs like Configuration&comma; SessionFactory and Session&period; These objects will continue to get scattered across the code throughout the Application&period; Moreover&comma; the Application code has to manually maintain and manage these objects&period; In the case of <b>Spring<&sol;b>&comma; the business objects can be highly configurable with the help of <i><b>IOC Container<&sol;b><&sol;i>&period; In simple words&comma; the state of an object can be externalized from the Application code&period; It means that now it is possible to use the Hibernate objects as <i><b>Spring Beans<&sol;b><&sol;i> and they can enjoy all the facilities that Spring provides&period;<&sol;p>&NewLine;<h2><b>Integration Spring and Hibernate<&sol;b><&sol;h2>&NewLine;<p>We can simply integrate Hibernate configuration with the Spring than struts 2 &comma; In hibernate framework file <i><b>hibernate&period;cfg&period;xml<&sol;b><&sol;i> using for the hibernate configuration with the application but in case of Spring there are no need to use this file we can simply configure with in the <i><b>Spring&period;xml<&sol;b><&sol;i> or <i><b>applicationContext&period;xml<&sol;b><&sol;i> configuration file&period; The following sections cover the various steps involved in the Spring-Hiberante integration along with a detailed explanation&period;<&sol;p>&NewLine;<h3><b>Using Hibernate Mapping file with Spring<&sol;b><&sol;h3>&NewLine;<&sol;div>&NewLine;<ol style&equals;"text-align&colon; left&semi;">&NewLine;<li>Creating Database and Table&lpar;<i><b>Employee Table<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating Employee Class&lpar;<i><b>Employee&period;java<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating the Hibernate Mapping file for Employee table&lpar;<i><b>Employee&period;hbm&period;xml<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating the Spring Configuration File &lpar;<i><b>spring&period;xml<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating the DAO class &lpar;<i><b>EmployeeDao&period;java<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating Application Class for using this<&sol;li>&NewLine;<&sol;ol>&NewLine;<h3><b>We can also use the Annotation for using this example with following steps&period;<&sol;b><&sol;h3>&NewLine;<ol style&equals;"text-align&colon; left&semi;">&NewLine;<li>Creating Database and Table&lpar;<i><b>Employee Table<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating Employee Class with using <b>&commat;Entity<&sol;b> annotation&lpar;<i><b>Employee&period;java<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating the Spring Configuration File &lpar;<i><b>spring&period;xml<&sol;b><&sol;i>&rpar; but creating bean with using annotation<&sol;li>&NewLine;<li>Creating the DAO class &lpar;<i><b>EmployeeDao&period;java<&sol;b><&sol;i>&rpar;<&sol;li>&NewLine;<li>Creating Application Class for using this<&sol;li>&NewLine;<&sol;ol>&NewLine;<p>Now first we see that example using annotation&period;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2012&sol;12&sol;hibernatespring&period;jpg" border&equals;"0" &sol;><&sol;div>&NewLine;<p><b>Step 1&period; Creating Database and Table&lpar;Employee Table&rpar;<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">CREATE TABLE Employee&lpar; &NewLine; EMPID INT NOT NULL AUTO&lowbar;INCREMENT&comma; &NewLine; NAME VARCHAR&lpar;20&rpar; NOT NULL&comma; &NewLine; AGE INT NOT NULL&comma; &NewLine; SALARY BIGINT NOT NULL&comma; &NewLine; PRIMARY KEY &lpar;ID&rpar; &NewLine;&rpar;&semi; &NewLine;<&sol;pre>&NewLine;<p><b><br &sol;>&NewLine;<&sol;b> <b>Step 2&colon; Creating Employee Class<&sol;b><br &sol;>&NewLine;<b><br &sol;>&NewLine;<&sol;b> <b>Employee&period;java<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">package com&period;dineshonjava&period;sdnext&period;domain&semi; &NewLine; &NewLine;import javax&period;persistence&period;Column&semi; &NewLine;import javax&period;persistence&period;Entity&semi; &NewLine;import javax&period;persistence&period;GeneratedValue&semi; &NewLine;import javax&period;persistence&period;GenerationType&semi; &NewLine;import javax&period;persistence&period;Id&semi; &NewLine;import javax&period;persistence&period;Table&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;&commat;Entity &NewLine;&commat;Table&lpar;name&equals;"Employee"&rpar; &NewLine;public class Employee &lbrace; &NewLine; &commat;Id &NewLine; &commat;Column&lpar;name&equals;"EMPID"&rpar; &NewLine; &commat;GeneratedValue&lpar;strategy&equals;GenerationType&period;AUTO&rpar; &NewLine; private int empid&semi; &NewLine; &NewLine; &commat;Column&lpar;name&equals;"NAME"&rpar; &NewLine; private String name&semi; &NewLine; &NewLine; &commat;Column&lpar;name&equals;"AGE"&rpar; &NewLine; private int age&semi; &NewLine; &NewLine; &commat;Column&lpar;name&equals;"SALARY"&rpar; &NewLine; private long salary&semi; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;return the empid &NewLine; &ast;&sol; &NewLine; public int getEmpid&lpar;&rpar; &lbrace; &NewLine; return empid&semi; &NewLine; &rcub; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;param empid the empid to set &NewLine; &ast;&sol; &NewLine; public void setEmpid&lpar;int empid&rpar; &lbrace; &NewLine; this&period;empid &equals; empid&semi; &NewLine; &rcub; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;return the name &NewLine; &ast;&sol; &NewLine; public String getName&lpar;&rpar; &lbrace; &NewLine; return name&semi; &NewLine; &rcub; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;param name the name to set &NewLine; &ast;&sol; &NewLine; public void setName&lpar;String name&rpar; &lbrace; &NewLine; this&period;name &equals; name&semi; &NewLine; &rcub; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;return the age &NewLine; &ast;&sol; &NewLine; public int getAge&lpar;&rpar; &lbrace; &NewLine; return age&semi; &NewLine; &rcub; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;param age the age to set &NewLine; &ast;&sol; &NewLine; public void setAge&lpar;int age&rpar; &lbrace; &NewLine; this&period;age &equals; age&semi; &NewLine; &rcub; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;return the salary &NewLine; &ast;&sol; &NewLine; public long getSalary&lpar;&rpar; &lbrace; &NewLine; return salary&semi; &NewLine; &rcub; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;param salary the salary to set &NewLine; &ast;&sol; &NewLine; public void setSalary&lpar;long salary&rpar; &lbrace; &NewLine; this&period;salary &equals; salary&semi; &NewLine; &rcub; &NewLine; &NewLine; public String toString&lpar;&rpar;&lbrace; &NewLine; return "EMPLOYEE&lbrace;empid- "&plus;this&period;empid&plus;" name- "&plus;this&period;name&plus; &NewLine; " age- "&plus;this&period;age&plus;" salary- "&plus;this&period;salary&plus;"&rcub;"&semi; &NewLine; &rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b><br &sol;>&NewLine;<&sol;b> <b>Step 3&colon; Creating the Spring Configuration File <&sol;b><br &sol;>&NewLine;<b>&lpar;spring&period;xml&rpar;<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;beans xmlns&colon;aop&equals;"http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;aop" xmlns&colon;context&equals;"http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;context" xmlns&colon;p&equals;"http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;p" xmlns&colon;> &NewLine;<b> &NewLine;<&sol;b> <b>Step 4&colon; Creating the DAO class <&sol;b> &NewLine;<b>&lpar;EmployeeDao&period;java&rpar;<&sol;b> &NewLine;<pre class&equals;"highlight">package com&period;dineshonjava&period;sdnext&period;dao&semi; &NewLine; &NewLine;import java&period;util&period;List&semi; &NewLine; &NewLine;import com&period;dineshonjava&period;sdnext&period;domain&period;Employee&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;public interface EmployeeDao &lbrace; &NewLine; &sol;&ast;&ast; &NewLine; &ast; This is the method to be used to create &NewLine; &ast; a record in the Employee table&period; &NewLine; &ast;&sol; &NewLine; void createEmployee&lpar;Employee employee&rpar;&semi; &NewLine; &sol;&ast;&ast; &NewLine; &ast; This is the method to be used to list down &NewLine; &ast; a record from the Employee table corresponding &NewLine; &ast; to a passed Employee id&period; &NewLine; &ast;&sol; &NewLine; Employee getEmployee&lpar;Integer empid&rpar;&semi; &NewLine; &sol;&ast;&ast; &NewLine; &ast; This is the method to be used to list down &NewLine; &ast; all the records from the Employee table&period; &NewLine; &ast;&sol; &NewLine; List listEmployees&lpar;&rpar;&semi; &NewLine; &sol;&ast;&ast; &NewLine; &ast; This is the method to be used to delete &NewLine; &ast; a record from the Employee table corresponding &NewLine; &ast; to a passed Employee id&period; &NewLine; &ast;&sol; &NewLine; void delete&lpar;Employee employee&rpar;&semi; &NewLine; &sol;&ast;&ast; &NewLine; &ast; This is the method to be used to update &NewLine; &ast; a record into the Employee table&period; &NewLine; &ast;&sol; &NewLine; void update&lpar;Employee employee&rpar;&semi; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b><br &sol;>&NewLine;<&sol;b> <b>SuperHibernateDaoSupport&period;java<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">package com&period;dineshonjava&period;sdnext&period;dao&period;util&semi; &NewLine; &NewLine;import org&period;springframework&period;orm&period;hibernate3&period;support&period;HibernateDaoSupport&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;public abstract class SuperHibernateDaoSupport extends HibernateDaoSupport &lbrace; &NewLine; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b><br &sol;>&NewLine;<&sol;b> <b>EmployeeDaoImpl&period;java<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">package com&period;dineshonjava&period;sdnext&period;dao&period;impl&semi; &NewLine; &NewLine;import java&period;util&period;List&semi; &NewLine; &NewLine;import org&period;springframework&period;stereotype&period;Repository&semi; &NewLine; &NewLine;import com&period;dineshonjava&period;sdnext&period;dao&period;EmployeeDao&semi; &NewLine;import com&period;dineshonjava&period;sdnext&period;dao&period;util&period;SuperHibernateDaoSupport&semi; &NewLine;import com&period;dineshonjava&period;sdnext&period;domain&period;Employee&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;&commat;Repository &NewLine;public class EmployeeDaoImpl extends SuperHibernateDaoSupport implements EmployeeDao &lbrace; &NewLine; &NewLine; &commat;Override &NewLine; public void createEmployee&lpar;Employee employee&rpar; &lbrace; &NewLine; getHibernateTemplate&lpar;&rpar;&period;saveOrUpdate&lpar;employee&rpar;&semi; &NewLine; &rcub; &NewLine; &NewLine; &commat;Override &NewLine; public Employee getEmployee&lpar;Integer empid&rpar; &lbrace; &NewLine; return &lpar;Employee&rpar; getHibernateTemplate&lpar;&rpar;&period;get&lpar;Employee&period;class&comma; empid&rpar;&semi; &NewLine; &rcub; &NewLine; &NewLine; &commat;Override &NewLine; public List listEmployees&lpar;&rpar; &lbrace; &NewLine; return getHibernateTemplate&lpar;&rpar;&period;find&lpar;"FROM EMPLOYEE"&rpar;&semi; &NewLine; &rcub; &NewLine; &NewLine; &commat;Override &NewLine; public void delete&lpar;Employee employee&rpar; &lbrace; &NewLine; getHibernateTemplate&lpar;&rpar;&period;delete&lpar;employee&rpar;&semi; &NewLine; &rcub; &NewLine; &NewLine; &commat;Override &NewLine; public void update&lpar;Employee employee&rpar; &lbrace; &NewLine; getHibernateTemplate&lpar;&rpar;&period;saveOrUpdate&lpar;employee&rpar;&semi; &NewLine; &rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b>Step 5&colon; Creating Application Class for using this<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">package com&period;dineshonjava&period;sdnext&period;main&semi; &NewLine; &NewLine;import org&period;springframework&period;context&period;ApplicationContext&semi; &NewLine;import org&period;springframework&period;context&period;support&period;ClassPathXmlApplicationContext&semi; &NewLine; &NewLine;import com&period;dineshonjava&period;sdnext&period;dao&period;EmployeeDao&semi; &NewLine;import com&period;dineshonjava&period;sdnext&period;domain&period;Employee&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;public class EmpMainApp &lbrace; &NewLine; &NewLine; &sol;&ast;&ast; &NewLine; &ast; &commat;param args &NewLine; &ast;&sol; &NewLine; public static void main&lpar;String&lbrack;&rsqb; args&rpar; &lbrace; &NewLine; &NewLine;ApplicationContext context &equals; new ClassPathXmlApplicationContext&lpar;"spring&period;xml"&rpar;&semi; &NewLine;EmployeeDao empDao &equals; &lpar;EmployeeDao&rpar; context&period;getBean&lpar;"employeeDaoImpl"&rpar;&semi; &NewLine; &NewLine; Employee employee &equals; new Employee&lpar;&rpar;&semi; &NewLine; employee&period;setName&lpar;"Dinesh"&rpar;&semi; &NewLine; employee&period;setAge&lpar;25&rpar;&semi; &NewLine; employee&period;setSalary&lpar;50000l&rpar;&semi; &NewLine; System&period;out&period;println&lpar;"------Records Creation--------" &rpar;&semi; &NewLine; empDao&period;createEmployee&lpar;employee&rpar;&semi; &NewLine; System&period;out&period;println&lpar;"------Listing Multiple Records--------" &rpar;&semi; &NewLine; List employees &equals; empDao&period;listEmployees&lpar;&rpar;&semi; &NewLine; for &lpar;Employee emp&colon; employees&rpar; &lbrace; &NewLine; System&period;out&period;print&lpar;emp&rpar;&semi; &NewLine; &rcub; &NewLine; System&period;out&period;println&lpar;"------find one Records--------" &rpar;&semi; &NewLine; Employee employee &equals; empDao&period;getEmployee&lpar;3&rpar;&semi; &NewLine; System&period;out&period;print&lpar;employee&rpar;&semi; &NewLine; System&period;out&period;println&lpar;"------Delete one Records--------" &rpar;&semi; &NewLine; empDao&period;delete&lpar;employee&rpar;&semi; &NewLine; &rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<div style&equals;"background-color&colon; &num;ff99cc&semi; border-width&colon; thin&semi; border&colon; solid&semi;"><b>Output&colon;<&sol;b><br &sol;>&NewLine;log4j&colon;WARN No appenders could be found for logger &lpar;org&period;springframework&period;context&period;support&period;ClassPathXmlApplicationContext&rpar;&period;<br &sol;>&NewLine;log4j&colon;WARN Please initialize the log4j system properly&period;<br &sol;>&NewLine;<b>------Records Creation--------<&sol;b><br &sol;>&NewLine;Hibernate&colon; insert into Employee &lpar;AGE&comma; NAME&comma; SALARY&rpar; values &lpar;&quest;&comma; &quest;&comma; &quest;&rpar;<br &sol;>&NewLine;<b>------Listing Multiple Records--------<&sol;b><br &sol;>&NewLine;Hibernate&colon; select employee0&lowbar;&period;EMPID as EMPID0&lowbar;&comma; employee0&lowbar;&period;AGE as AGE0&lowbar;&comma; employee0&lowbar;&period;NAME as NAME0&lowbar;&comma; employee0&lowbar;&period;SALARY as SALARY0&lowbar; from Employee employee0&lowbar;<br &sol;>&NewLine;EMPLOYEE&lbrace;empid- 1 name- Dinesh age- 25 salary- 50000&rcub;EMPLOYEE&lbrace;empid- 2 name- Anamika age- 20 salary- 30000&rcub;EMPLOYEE&lbrace;empid- 3 name- Nimmo age- 24 salary- 30020&rcub;EMPLOYEE&lbrace;empid- 4 name- Adesh age- 24 salary- 30011&rcub;EMPLOYEE&lbrace;empid- 5 name- Vinesh age- 22 salary- 20011&rcub;EMPLOYEE&lbrace;empid- 6 name- Rajesh age- 25 salary- 50000&rcub;EMPLOYEE&lbrace;empid- 7 name- DAV age- 21 salary- 50000&rcub;<br &sol;>&NewLine;<b>------find one Records--------<&sol;b><br &sol;>&NewLine;Hibernate&colon; select employee0&lowbar;&period;EMPID as EMPID0&lowbar;0&lowbar;&comma; employee0&lowbar;&period;AGE as AGE0&lowbar;0&lowbar;&comma; employee0&lowbar;&period;NAME as NAME0&lowbar;0&lowbar;&comma; employee0&lowbar;&period;SALARY as SALARY0&lowbar;0&lowbar; from Employee employee0&lowbar; where employee0&lowbar;&period;EMPID&equals;&quest;<br &sol;>&NewLine;EMPLOYEE&lbrace;empid- 3 name- Nimmo age- 24 salary- 30020&rcub;<br &sol;>&NewLine;<b>------Delete one Records--------<&sol;b><br &sol;>&NewLine;Hibernate&colon; delete from Employee where EMPID&equals;&quest;<&sol;div>&NewLine;<p><b>Source Code from Git Link<&sol;b><&sol;p>&NewLine;<p><a href&equals;"https&colon;&sol;&sol;github&period;com&sol;DOJ-SoftwareConsultant&sol;SpringHibernateDemo&period;git">https&colon;&sol;&sol;github&period;com&sol;DOJ-SoftwareConsultant&sol;SpringHibernateDemo&period;git<&sol;a><&sol;p>&NewLine;<div style&equals;"text-align&colon; center&semi;"><b>&lt&semi;&lt&semi;<&sol;b><b><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;transaction-management-in-spring&sol;">Transaction Management<&sol;a><&sol;b><&sol;b><b> &vert;<a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-tutorial&sol;">index<&sol;a>&vert; <&sol;b><b><b><&sol;b><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-web-mvc-framework-chapter-38&sol;">Spring Web MVC Framework<&sol;a><&sol;b><&sol;b><b>&gt&semi;&gt&semi;<&sol;b><&sol;div>&NewLine;<&sol;div>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<&sol;div>&NewLine;<div class&equals;"wp-post-navigation"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-pre"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;declarative-transaction-management&sol;">Previous<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-next"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-aop-transaction-management-in&sol;">Next<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;<&sol;div>&NewLine;<script type&equals;"text&sol;javascript">&NewLine;jQuery&lpar;document&rpar;&period;ready&lpar;function&lpar;&dollar;&rpar; &lbrace;&NewLine; &dollar;&period;post&lpar;'https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-admin&sol;admin-ajax&period;php'&comma; &lbrace;action&colon; 'mts&lowbar;view&lowbar;count'&comma; id&colon; '626'&rcub;&rpar;&semi;&NewLine;&rcub;&rpar;&semi;&NewLine;<&sol;script>

Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

4 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

4 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

4 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

4 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

4 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

4 years ago