Spring 3.0 MVC with Hibernate 3.0 CRUD Example

In this example show how to write a simple web based application with CRUD  operation using Spring3 MVC Framwork with Hibernate3 using Annotation, which can handle CRUD inside its controllers. To start with it, let us have working STS IDE in place and follow the following steps to develop a Dynamic Form based Web Application using Spring Web Framework:

Related Tutorials
  1. Spring Tutorial
  2. Spring MVC Web Tutorial
  3. Spring Boot Tutorial
  4. Spring Security Tutorial

Step 1: Create a Database DAVDB on MySql Database and also we create Employee table on this database.
CREATE TABLE Employee(
   EMPID   INT NOT NULL AUTO_INCREMENT,
   EMPNAME VARCHAR(20) NOT NULL,
   EMPAGE  INT NOT NULL,
   SALARY BIGINT NOT NULL,
   ADDRESS VARCHAR(20) NOT NULL
   PRIMARY KEY (ID)
);

Step 2: Create a database.properties for database configuration information in the resources folder under src folder in the created project.
database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/DAVDB
database.user=root
database.password=root
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update

Step 3: Create a Dynamic Web Project with a name Spring3HibernateApp and create packages com.dineshonjava.controller, com.dineshonjava.bean, com.dineshonjava.dao, com.dineshonjava.service, com.dineshonjava.model under the src folder in the created project.

Step 4: Add below mentioned Spring 3.0 and Hibernate 3.0 related libraries and other libraries into the folder WebRoot/WEB-INF/lib
Spring MVC with Hibernate CRUD Example
Step 5: Create a Java class EmployeeController, EmployeeBean, Employee, EmployeeDao, EmployeeDaoImpl, EmployeeService, EmployeeServiceImpl under the respective packages..

Step 6: Create Spring configuration files web.xml and sdnext-servlet.xml under the WebRoot/WEB-INF/ and WebRoot/WEB-INF/config folders.

Step 7: Create a sub-folder with a name views under the WebRoot/WEB-INF folder. Create a view file addEmployee.jsp, employeesList.jsp and index.jsp under this sub-folder.

Step 8: The final step is to create the content of all the source and configuration files name sdnext-servlet.xml under the sub-folder /WebRoot/WEB-INF/config and export the application as explained below.
Spring MVC  Hibernate CRUD Example

Application Architecture

We will have a layered architecture for our demo application. The database will be accessed by a Data Access layer popularly called as DAO Layer. This layer will use Hibernate API to interact with database. The DAO layer will be invoked by a service layer. In our application we will have a Service interface called EmployeeService.
Spring and Hibernate CRUD Example

EmployeeBean.java
package com.dineshonjava.bean;

/**
 * @author Dinesh Rajput
 *
 */
public class EmployeeBean {
 private Integer id;
 private String name;
 private Integer age;
 private Long salary;
 private String address;
 
 public Long getSalary() {
  return salary;
 }
 public void setSalary(Long salary) {
  this.salary = salary;
 }
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public Integer getAge() {
  return age;
 }
 public void setAge(Integer age) {
  this.age = age;
 }
 public String getAddress() {
  return address;
 }
 public void setAddress(String address) {
  this.address = address;
 }
}
Employee.java
package com.dineshonjava.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * @author Dinesh Rajput
 *
 */
@Entity
@Table(name="Employee")
public class Employee implements Serializable{

 private static final long serialVersionUID = -723583058586873479L;
 
 @Id
 @GeneratedValue(strategy=GenerationType.AUTO)
 @Column(name = "empid")
 private Integer empId;
 
 @Column(name="empname")
 private String empName;
 
 @Column(name="empaddress")
 private String empAddress;
 
 @Column(name="salary")
 private Long salary;
 
 @Column(name="empAge")
 private Integer empAge;

 public Integer getEmpId() {
  return empId;
 }

 public void setEmpId(Integer empId) {
  this.empId = empId;
 }

 public String getEmpName() {
  return empName;
 }

 public void setEmpName(String empName) {
  this.empName = empName;
 }

 public String getEmpAddress() {
  return empAddress;
 }

 public void setEmpAddress(String empAddress) {
  this.empAddress = empAddress;
 }

 public Long getSalary() {
  return salary;
 }

 public void setSalary(Long salary) {
  this.salary = salary;
 }

 public Integer getEmpAge() {
  return empAge;
 }

 public void setEmpAge(Integer empAge) {
  this.empAge = empAge;
 }
}
EmployeeDao.java
package com.dineshonjava.dao;

import java.util.List;

import com.dineshonjava.model.Employee;

/**
 * @author Dinesh Rajput
 *
 */
public interface EmployeeDao {
 
 public void addEmployee(Employee employee);

 public List<Employee> listEmployeess();
 
 public Employee getEmployee(int empid);
 
 public void deleteEmployee(Employee employee);
}
EmployeeDaoImpl.java
package com.dineshonjava.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.dineshonjava.model.Employee;

/**
 * @author Dinesh Rajput
 *
 */
@Repository("employeeDao")
public class EmployeeDaoImpl implements EmployeeDao {

 @Autowired
 private SessionFactory sessionFactory;
 
 public void addEmployee(Employee employee) {
   sessionFactory.getCurrentSession().saveOrUpdate(employee);
 }

 @SuppressWarnings("unchecked")
 public List<Employee> listEmployeess() {
  return (List<Employee>) sessionFactory.getCurrentSession().createCriteria(Employee.class).list();
 }

 public Employee getEmployee(int empid) {
  return (Employee) sessionFactory.getCurrentSession().get(Employee.class, empid);
 }

 public void deleteEmployee(Employee employee) {
  sessionFactory.getCurrentSession().createQuery("DELETE FROM Employee WHERE empid = "+employee.getEmpId()).executeUpdate();
 }
}
EmployeeService.java
package com.dineshonjava.service;

import java.util.List;

import com.dineshonjava.model.Employee;

/**
 * @author Dinesh Rajput
 *
 */
public interface EmployeeService {
 
 public void addEmployee(Employee employee);

 public List<Employee> listEmployeess();
 
 public Employee getEmployee(int empid);
 
 public void deleteEmployee(Employee employee);
}
EmployeeServiceImpl.java
package com.dineshonjava.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dineshonjava.dao.EmployeeDao;
import com.dineshonjava.model.Employee;

/**
 * @author Dinesh Rajput
 *
 */
@Service("employeeService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EmployeeServiceImpl implements EmployeeService {

 @Autowired
 private EmployeeDao employeeDao;
 
 @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
 public void addEmployee(Employee employee) {
  employeeDao.addEmployee(employee);
 }
 
 public List<Employee> listEmployeess() {
  return employeeDao.listEmployeess();
 }

 public Employee getEmployee(int empid) {
  return employeeDao.getEmployee(empid);
 }
 
 public void deleteEmployee(Employee employee) {
  employeeDao.deleteEmployee(employee);
 }

}
EmployeeController.java
package com.dineshonjava.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.dineshonjava.bean.EmployeeBean;
import com.dineshonjava.model.Employee;
import com.dineshonjava.service.EmployeeService;

/**
 * @author Dinesh Rajput
 *
 */
@Controller
public class EmployeeController {
 
 @Autowired
 private EmployeeService employeeService;
 
@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView saveEmployee(@ModelAttribute("command")EmployeeBean employeeBean, 
   BindingResult result) {
  Employee employee = prepareModel(employeeBean);
  employeeService.addEmployee(employee);
  return new ModelAndView("redirect:/add.html");
 }

 @RequestMapping(value="/employees", method = RequestMethod.GET)
 public ModelAndView listEmployees() {
  Map<String Object> model = new HashMap<String Object>();
  model.put("employees",  prepareListofBean(employeeService.listEmployeess()));
  return new ModelAndView("employeesList", model);
 }

 @RequestMapping(value = "/add", method = RequestMethod.GET)
 public ModelAndView addEmployee(@ModelAttribute("command")EmployeeBean employeeBean,
   BindingResult result) {
  Map<String, Object> model = new HashMap<String, Object>();
  model.put("employees",  prepareListofBean(employeeService.listEmployeess()));
  return new ModelAndView("addEmployee", model);
 }
 
@RequestMapping(value = "/index", method = RequestMethod.GET)
public ModelAndView welcome() {
  return new ModelAndView("index");
 }

@RequestMapping(value = "/delete", method = RequestMethod.GET)
public ModelAndView editEmployee(@ModelAttribute("command")EmployeeBean employeeBean,
   BindingResult result) {
  employeeService.deleteEmployee(prepareModel(employeeBean));
  Map<String, Object> model = new HashMap<String, Object>();
  model.put("employee", null);
  model.put("employees",  prepareListofBean(employeeService.listEmployeess()));
  return new ModelAndView("addEmployee", model);
 }
 
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public ModelAndView deleteEmployee(@ModelAttribute("command")EmployeeBean employeeBean,
   BindingResult result) {
  Map<String, Object> model = new HashMap<String, Object>();
  model.put("employee", prepareEmployeeBean(employeeService.getEmployee(employeeBean.getId())));
  model.put("employees",  prepareListofBean(employeeService.listEmployeess()));
  return new ModelAndView("addEmployee", model);
 }
 
 private Employee prepareModel(EmployeeBean employeeBean){
  Employee employee = new Employee();
  employee.setEmpAddress(employeeBean.getAddress());
  employee.setEmpAge(employeeBean.getAge());
  employee.setEmpName(employeeBean.getName());
  employee.setSalary(employeeBean.getSalary());
  employee.setEmpId(employeeBean.getId());
  employeeBean.setId(null);
  return employee;
 }
 
 private List<EmployeeBean> prepareListofBean(List<Employee> employees){
  List<employeebean> beans = null;
  if(employees != null && !employees.isEmpty()){
   beans = new ArrayList<EmployeeBean>();
   EmployeeBean bean = null;
   for(Employee employee : employees){
    bean = new EmployeeBean();
    bean.setName(employee.getEmpName());
    bean.setId(employee.getEmpId());
    bean.setAddress(employee.getEmpAddress());
    bean.setSalary(employee.getSalary());
    bean.setAge(employee.getEmpAge());
    beans.add(bean);
   }
  }
  return beans;
 }
 
 private EmployeeBean prepareEmployeeBean(Employee employee){
  EmployeeBean bean = new EmployeeBean();
  bean.setAddress(employee.getEmpAddress());
  bean.setAge(employee.getEmpAge());
  bean.setName(employee.getEmpName());
  bean.setSalary(employee.getSalary());
  bean.setId(employee.getEmpId());
  return bean;
 }
}
Spring Web configuration file web.xml
<web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

   <servlet>
     <servlet-name>sdnext</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     <init-param>
            <param-name>contextConfigLocation</param-name><param-value>/WEB-INF/config/sdnext-servlet.xml</param-value></init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>

 <servlet-mapping>
  <servlet-name>sdnext</servlet-name>
  <url-pattern>*.html</url-pattern>
 </servlet-mapping>

 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>

</web-app>


Spring Web configuration file sdnext-servlet.xml
<beans xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<context:property-placeholder location="classpath:resources/database.properties">
</context:property-placeholder>
<context:component-scan base-package="com.dineshonjava">
</context:component-scan>

<tx:annotation-driven transaction-manager="hibernateTransactionManager">
</tx:annotation-driven>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="jspViewResolver">
 <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
 <property name="prefix" value="/WEB-INF/views/"></property>
 <property name="suffix" value=".jsp"></property>
</bean>

<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
 <property name="driverClassName" value="${database.driver}"></property>
 <property name="url" value="${database.url}"></property>
 <property name="username" value="${database.user}"></property>
 <property name="password" value="${database.password}"></property>
</bean>

<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory">
 <property name="dataSource" ref="dataSource"></property>
 <property name="annotatedClasses">
  <list>
   <value>com.dineshonjava.model.Employee</value>
  </list>
 </property>
 <property name="hibernateProperties">
 <props>
  <prop key="hibernate.dialect">${hibernate.dialect}</prop>
  <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
  <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}  </prop>    
        </props>
      </property>
</bean>

  <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="hibernateTransactionManager">
 <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
</beans>

addEmployee.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>Spring MVC Form Handling</title>
 </head>
 <body>
  <h2>Add Employee Data</h2>
  <form:form method="POST" action="/sdnext/save.html">
      <table>
       <tr>
           <td><form:label path="id">Employee ID:</form:label></td>
           <td><form:input path="id" value="${employee.id}" readonly="true"/></td>
       </tr>
       <tr>
           <td><form:label path="name">Employee Name:</form:label></td>
           <td><form:input path="name" value="${employee.name}"/></td>
       </tr>
       <tr>
           <td><form:label path="age">Employee Age:</form:label></td>
           <td><form:input path="age" value="${employee.age}"/></td>
       </tr>
       <tr>
           <td><form:label path="salary">Employee Salary:</form:label></td>
           <td><form:input path="salary" value="${employee.salary}"/></td>
       </tr>
       
       <tr>
           <td><form:label path="address">Employee Address:</form:label></td>
                    <td><form:input path="address" value="${employee.address}"/></td>
       </tr>
          <tr>
         <td colspan="2"><input type="submit" value="Submit"/></td>
        </tr>
   </table> 
  </form:form>
  
  <c:if test="${!empty employees}">
  <h2>List Employees</h2>
 <table align="left" border="1">
  <tr>
   <th>Employee ID</th>
   <th>Employee Name</th>
   <th>Employee Age</th>
   <th>Employee Salary</th>
   <th>Employee Address</th>
           <th>Actions on Row</th>
  </tr>

  <c:forEach items="${employees}" var="employee">
   <tr>
    <td><c:out value="${employee.id}"/></td>
    <td><c:out value="${employee.name}"/></td>
    <td><c:out value="${employee.age}"/></td>
    <td><c:out value="${employee.salary}"/></td>
    <td><c:out value="${employee.address}"/></td>
    <td align="center"><a href="edit.html?id=${employee.id}">Edit</a> | <a href="delete.html?id=${employee.id}">Delete</a></td>
   </tr>
  </c:forEach>
 </table>
</c:if>
 </body>
</html>

employeesList.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>All Employees</title>
</head>
<body>
<h1>List Employees</h1>
<h3><a href="add.html">Add More Employee</a></h3>

<c:if test="${!empty employees}">
 <table align="left" border="1">
  <tr>
   <th>Employee ID</th>
   <th>Employee Name</th>
   <th>Employee Age</th>
   <th>Employee Salary</th>
   <th>Employee Address</th>
  </tr>

  <c:forEach items="${employees}" var="employee">
   <tr>
    <td><c:out value="${employee.id}"/></td>
    <td><c:out value="${employee.name}"/></td>
    <td><c:out value="${employee.age}"/></td>
    <td><c:out value="${employee.salary}"/></td>
    <td><c:out value="${employee.address}"/></td>
   </tr>
  </c:forEach>
 </table>
</c:if>
</body>
</html>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Spring3MVC with Hibernate3 CRUD Example using Annotations</title>
  </head>
  <body>
    <h2>Spring3MVC with Hibernate3 CRUD Example using Annotations</h2>
    <h2>1. <a href="employees.html">List of Employees</a></h2>
    <h2>2. <a href="add.html">Add Employee</a></h2>
  </body>
</html>
Once you are done with creating source and configuration files, export your application. Right click on your application and use Export-> WAR File option and save your Spring3HibernateApp.war file in Tomcat's webapps folder.

Now start your Tomcat server and make sure you are able to access other web pages from webapps folder using a standard browser. Now try a URL http://localhost:8080/sdnext/ and you should see the following result if everything is fine with your Spring Web Application:

Spring MVC with Hibernate CRUD
1. CREATE EMPLOYEE: Now click on the Add Employee link we get the following form for Create Employee.
CRUD Example Spring and Hibernate
 Now click on the Submit button data are saved to the employee table on the database. And we get the following 
Spring and Hibernate
 2 READ EMLOYEE : Now click on the List of Employee link we get the following employee list.
Spring and Hibernate Application
 3.UPDATE EMPLOYEE: for update the emloyee form we have to click on the Edit link in the table of employees show on the broswer.
we click Edit button for fifth record of table the >>
CRUD Spring and Hibernate
 Now update the name field value from Sweety to Sweety Rajput and salary filed value 35000 to 36000 and submit the data after submit we get the following updaed table against fifth row of table.
Spring3 Hibernate
4.DELETE EMPLOYEE: Now we want to delete the one employee record from the table the we click on the delete button. we want to delete fifth records of the above table now click on the delete button of the corresponding records and we get the final list as below.
Spring Hibernate
 Download Source code
Spring3HibernateApp.zip

 



148 comments:

  1. Hi dinesh ..how to add one or more field in this application i tried but error is coming ..so pls add one or more fields in this application..

    ReplyDelete
    Replies
    1. Hi .. Please tell me what error is coming.
      If you want to add more fields on the Employee Data Form just likes Employee Mobile, Employee Dept etc. Then you have to do just add property to EmployeeBean.java as well as add to Employee.java class after that you have drop the previous schema of DB for this you have to some minor change in the database.properties file.
      -------------------------------------
      hibernate.hbm2ddl.auto=create
      -----------------------------------
      this line add instead of following line
      ----------------------------------
      hibernate.hbm2ddl.auto=update
      --------------------------------
      then final you get..


      database.driver=com.mysql.jdbc.Driver
      database.url=jdbc:mysql://localhost:3306/DAVDB
      database.user=root
      database.password=root
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
      hibernate.show_sql=true
      hibernate.hbm2ddl.auto=create

      Delete
  2. hi Dinesh
    i am getting error in following line..i dont know which jar file is missing...plz help me
    --------------------------------------------
    Employee employee = prepareModel(employeeBean);
    ERROR:The method prepareModel(EmployeeBean) is undefined for the type EmployeeController

    ReplyDelete
    Replies
    1. hello... this problem is not due to you missing some jar files but it is because of you missing to define the method prepareModel(employeeBean) in the EmployeeController.java file, now You have to the define the above method please see EmployeeController.java file in the above code on this post.

      Thanks

      Delete
    2. Thanks.now it's working.am beginner to spring framework..your tutorial helped me lot...

      Delete
    3. most welcome.. :) If you have any problem then we definitely help you..

      Thanks

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi dinesh ..how to add one or more field in this application i tried but error is coming ..so pls add one or more fields in this application..



    type Exception report

    message An exception occurred processing JSP page /WEB-INF/views/addEmployee.jsp at line 55

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: An exception occurred processing JSP page


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)

    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.34 logs.

    ReplyDelete
  5. org.apache.jasper.JasperException: org.springframework.beans.NotReadablePropertyException: Invalid property 'mobile' of bean class [com.dineshonjava.bean.EmployeeBean]: Bean property 'mobile' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

    org.springframework.beans.NotReadablePropertyException: Invalid property 'mobile' of bean class [com.dineshonjava.bean.EmployeeBean]: Bean property 'mobile' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

    ReplyDelete
    Replies
    1. Hi Prathaban,

      org.apache.jasper.JasperException: org.springframework.beans.NotReadablePropertyException is due to You have added one more field like mobile into Employee.java class but you are not adding to the EmployeeBean.java so please also adding same field on this class as well as Employee.java both.
      Then try again we sure you get success to run the application.

      Thanks,

      Dinesh

      Delete
  6. Hi i Have already added both employee.java, and employeebean.java but exception is came.

    ReplyDelete
    Replies
    1. Hi Prathaban,

      As per as your exception "org.apache.jasper.JasperException: org.springframework.beans.NotReadablePropertyException" you are missing to adding the "mobile" field into the "EmployeeBean.java" please check the case of field of whatever are added.

      Please provide me the source of the following file.
      addEmployee.jsp
      Employee.java
      EmployeeBean.java
      database.properties

      on the comment field or mail me on the admin@dineshonjava.com
      then We will able to help you.

      Thanks,

      Dinesh

      Delete
    2. Do one more thing please check the setter and getter methods of the fields which you added .
      as follows.
      *************************************
      private String mobile;
      public String getMobile(){
      return this.mobile;
      }
      public void setMobile(String mobile){
      this.mobile = mobile;
      }
      *******************************************
      on the both classes.
      Employee.java
      EmployeeBean.java

      Delete
  7. i added but same error is came

    Thanks
    prathaban

    ReplyDelete
    Replies
    1. Hi,

      Now your application is working or not after adding extra field.

      Thanks,
      Dinesh

      Delete
  8. input is not taking any value , all input type is disable

    ReplyDelete
  9. Dinesh Rajput7 February 2013 11:29 pm
    Hi,

    Now your application is working or not after adding extra field.

    Thanks,
    Dinesh

    reply:
    i tried but did not working dinesh..

    Thanks
    prtthaban j

    ReplyDelete
    Replies
    1. Are you deploying that code which I have been sent to you after adding one more field "mobile".

      I am asking this code is not working or you are adding some more fields except "mobile".

      You can touch with us any weekend any time.

      Delete
  10. HI Dinesh
    i have adding some more fields.except mobile .i have seened same error.

    thanks
    prathaban j

    ReplyDelete
  11. hi dinesh !
    when am running this program on eclipse and tomcat as server ! It is showing error

    SEVERE: Unable to process Jar entry [com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class] from Jar [jar:file:/C:/Users/Deepak/Documents/negid/.metadata/.plugins/org.eclipse.wst.server.core/tmp5/wtpwebapps/Spring3HibernateApp/WEB-INF/lib/icu4j-2.6.1.jar!/] for annotations
    org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60

    ReplyDelete
    Replies
    1. Hi Deepak,

      Please let me know which server is used by you for this application. All application in this tutorial we are used Tomcat 7.0. So please use this server and try to run.

      As per as your exception we found that you missing the jar file "icu4j-2.6.1.jar" please download it and add to the class path. then try.

      Thanks,

      Dinesh

      Delete
  12. i m getting error like: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
    Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]

    ReplyDelete
    Replies
    1. Hi Sagar,

      May be you are missing jar file (spring-tx-3.0.2.RELEASE.jar) or you are using old version of this jar file. If you are using same code of the servlet-context.xml file as per as shown in this tutorial file sdnext-servlet.xml then you have to add the latest jar file(spring-tx-3.0.2.RELEASE.jar) and deploy.

      And also you can download the attached zip associated with this tutorial have all required jars.

      Thanks
      Dinesh

      Delete
  13. Hi Dinesh! Great tutorial but i have a question with EmployeeBean and Employee classes, why you use the EmployeeBean in the controller class if you have the Employee class with the annotations?

    ReplyDelete
    Replies
    1. Hi Friend,

      First of all thanks for nice compliment.

      In high level project in the enterprise it way of more modularize of capturing data from front end and after applying business need and set that data to the other object which communicate with the database.

      In this example EmployeeBean used as a bean for display its may be have more fields than Employee class. Employee class using just purpose for DTO between DB & Application. Its have table structured data fields. Because of this reason we used EmployeeBean as separate from Employee Class.

      I hope you will understand of big requirement in this small application. If you have any more questions you can meet me on same and admin@dineshonjava.com.

      Thanks
      Dinesh

      Delete
  14. In this particular tutorial is very good to read and having clear idea for us.
    Thank you !!!

    ReplyDelete
    Replies
    1. Welcome mr. muthu, stay tune..

      Thanks
      Dinesh

      Delete
  15. This comment has been removed by the author.

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Hello Dinesh,
    I followed the tutorial and used the same code which you provided, but i am not able to add or update the records. After clicking the submit i get the following errors:
    HTTP Status 404 - /sdnext/save.html

    --------------------------------------------------------------------------------

    type Status report

    message /sdnext/save.html

    description The requested resource is not available.

    Please help me soon.
    Thanks,
    Manish Kumar

    ReplyDelete
    Replies
    1. Hi Manish,

      Please update the "context root(sdnext)" as per as your application configuration in jsp files. Then your application is successfully running.

      After that you are not getting success then mail me your code at admin@dineshonjava.com for better response.

      Thanks,
      Dinesh

      Delete
    2. Hello Dinesh,
      I tried to fix the issue but did not succeed. So, I mailed you the code, please have a look at it and help me.
      Thanks
      Manish

      Delete
    3. Thanks Dinesh.. it got resolved.. Your tutorial helped me very much..!

      Delete
    4. Ok Manish,

      If you got any problems or questions in the future then directly talk to me at same.

      Thanks,
      Dinesh

      Delete
    5. Sir,I am getting the same problem and am unable to fix it. Can u pls tell me what to change?

      Delete
    6. Hi Divya,

      Please change the context root of your project in place of "sdnext".
      Then you get successfully running project.

      If you have still same problem then you can mail your project at admin@dineshonjava.com

      Thanks,
      Dinesh

      Delete
    7. hi dinesh when i try to execute this example in my system i got the following error can u please tel me what changes totally i need to do after import this source code to eclipse
      org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60
      at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:133)

      Delete
  18. Hi i had tried this example but im getting error like "The requested resource (/sdnext/) is not available".How could i resolve this.

    ReplyDelete
    Replies
    1. Hi Harish,
      Please replace the "sdnext" context path with your project name.

      Please try it if not success then revert again or send your query at admin@dineshonjava.com.

      Thanks
      Dinesh

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Hi Dinesh,

      I got the output by replacing the context path.

      Delete
    4. Greate Harish,

      Keep learning with dineshonjava.com and please like it on facebook as well.

      Very Regards,

      Dinesh

      Delete
  19. Anybody there?Kindly reply to ma question as i deployed it perfectly but im not getting the output

    ReplyDelete
  20. Hi Dinesh i am getting this error please help me to solve it

    DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dineshonjava.service.EmployeeService com.dineshonjava.controller.EmployeeController.employe

    ReplyDelete
    Replies
    1. Dear Venky,
      You are missing to autowired one property EmployeeService to EmployeeController please verify this file.
      Regards
      Dinesh

      Delete
  21. HI DINESH ,

    PLEASE UPLOAD VIDEO ADD MORE FIELDS IN THIS APPLICATION I AM TRYING MORE THEN TIMES NOT able to add MORE FIELDS ... PLEASE HELP ME ....UPLOAD VIEDO DOC Spring 3.0 MVC with Hibernate 3.0 CRUD Example

    THANKS
    PRATHABAN

    ReplyDelete
  22. why u add 2 classes EmployeeBean and Employee. can i used annotation on my model class only, without bean?. it just wasting time, and unefficient for me

    ReplyDelete
    Replies
    1. Yes you can use only one class either EmployeeBean or Employee. Here I am just using both class whenever Bean class has extra properties than Model class.

      Delete
  23. Hi Dinesh,
    While executing the project i faced below issue kindly help me in detail to resolve that error
    HTTP Status 404 - /sdnext/

    ReplyDelete
    Replies
    1. Hi Wasif,

      Please update the "context root(sdnext)" as per as your application configuration.

      or
      Make new dynamic web application and paste all code files in your application. Its error due to application context root.

      If not understand then you can touch with me at admin@dineshonjava.com with code

      Thanks,
      Dinesh

      Delete
    2. Hi Dinesh,

      I have mailed you the full code,bout hadn't got any reply from your side.
      Please help.I am awaiting your reply

      Delete
    3. Hi Dinesh,

      I have mailed you the full code,bout hadn't got any reply from your side.
      Please help.I am awaiting your reply

      Delete
    4. Hi Wasif,
      I am sorry for delay in response.

      Could please send again the full code at admin@dineshonjava.com.
      In mail box I have not any code from your site. So please send again.

      Thanks,
      Anamika

      Delete
    5. Hi Anamika,

      I have already send through hightail and waiting for your effective reply..
      I am very grateful to you

      Thanks,
      Wasif

      Delete
    6. Hi Anamika,

      Please help..

      Thanks,
      Wasif

      Delete
  24. Hi Dinesh,

    Can you elaborate me about @ModelAttribute and why to use command value in the ModelAttribute annoatation.

    ReplyDelete
    Replies
    1. Hi Udaykiran,

      An @ModelAttribute on a method argument indicates the argument should be retrieved from the model. If not present in the model, the argument should be instantiated first and then added to the model. Once present in the model, the argument's fields should be populated from all request parameters that have matching names. This is known as data binding in Spring MVC, a very useful mechanism that saves you from having to parse each form field individually.

      For example- its populate model data fetching from JSP or another view templates..
      public String saveEmployee(@ModelAttribute EmployeeBean bean) {
      empDao.save(bean);
      }

      or we can also use ModelAttribute as on method like below.. it populate model after fetching from database.

      @ModelAttribute
      public String getEmployee(int empId) {
      empDao.getEmployee(empId);
      }

      And another point about "command" value in model attribute. Its mean nothing but it fetching the name of model attribute from command attribute of JSTL's from tag.
      Example-
      <form:form name="empForm" commandName="emoployeeBean" action="saveEmployee/">

      Here if you not give commandName attribute in JSTL form tag then by default name as model name starting with small letter.

      Thanks,
      Dinesh

      Delete
    2. Thanks Dinesh. Can you please tell me how to implement login page using Spring MVC and hibernate. In the above example how can i implement login form for an employee.

      Delete
    3. http://www.dineshonjava.com/2013/02/spring-security-form-based-login-example.html#.UkBfyoanos8

      Delete
    4. Hi Dinesh your help is much appreciated and I want to insert CSS sheet into the code u wrote but the style sheet is not inserting. I loaded the file in the WebRoot-> images directory .the name of the style sheet is style.css. When i am giving reference to link like href="/images/style.css the file is not loading. Can you please help me. does i need to add any servlet for the CSS files.

      Delete
  25. Hi Dinesh,
    I have downloaded your sample code, while running the application I am getting exception as :
    SEVERE: Unable to process Jar entry [com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class] from Jar [jar:file:/D:/PMS/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Spring3HibernateApp/WEB-INF/lib/icu4j-2.6.1.jar!/] for annotations
    org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60


    Inspite of this exception I am unable to see the first page of application but when I try to add record it gives me 505 exception:

    HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not insert: [com.dineshonjava.model.Employee]


    Please help me in getting this correct!!!

    ReplyDelete
    Replies
    1. Sorry for the typo- I wanted to say "Inspite of this exception I am able to see the first page of application but when I try to add record it gives me 505 exception" instead of "unable to see"

      Delete
    2. Hi Sunayana,

      Please create database before deploying application. Your application unable to save data into DB.
      Try it after that you get same problem, touch with us on admin@dineshonjava.com and also like with facebook for regular update.

      Thanks,
      Dinesh

      Delete
    3. Hi Dinesh,
      Thanks for your prompt reply!! The issue was: I created table before implementing the application, but mistakenly an extra field was created in table. Now that I have removed that extra field, I do no get any exception and the application is running fine!

      Thanks,
      Sunayana

      Delete
    4. Hi Sunayana,

      Please like with facebook for regular update.

      Thanks,
      Dinesh

      Delete
  26. Hi dinesh,
    i m new in spring.ad your demo shows mw following error.

    Failed to read candidate component class: URL [jar:file:/Volumes/DATA/apache-tomcat-7.0.14/webapps/spring/WEB-INF/lib/icu4j-2.6.1.jar!/com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 48188

    ad can u pls tell me the flow of this app

    ReplyDelete
    Replies
    1. i hav download new jar file from jarfinder.
      still i will nt work

      pls help

      Delete
    2. Hi Ketul,

      I think your application still not getting /icu4j-2.6.1.jar file. Please build class path again.

      Thanks,
      Dinesh

      Delete
    3. Can u pls tell me the flow how this app work
      means step by step flow

      Delete
  27. Hi Dinesh,
    Tutorials provide by you are awesome.You have provided almost everything in java.Its very good for newbie like us to develop there skills in java.And you keep on responding on each and every comments.Thank You so much for all your efforts.

    I am using oracle 11g database
    I have made following changes in the code

    In sdnext-servlet.xml









    I have used ojdbc14.jar

    When i click Add Employees I am getting this exception

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.hibernate.exception.GenericJDBCException: Cannot open connection

    java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
    oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)



    ReplyDelete
  28. This are the changes which i made
    In database properties
    connection.driver_class=oracle.jdbc.driver.OracleDriver
    connection.url=jdbc:oracle:thin:@localhost:1521:xe
    connection.username=system
    connection.password=Hanuman123
    hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
    hibernate.show_sql=true
    hibernate.hbm2ddl.auto=update

    in sdnext-servlet.xml







    Kindly help me in this regard
    Thanks in advace

    ReplyDelete
    Replies
    1. Hi Friends,

      Thanks for your encouraging and nice complementary comment.
      First thing is please update one more thing in properties file.
      hibernate.hbm2ddl.auto=create (only for you first time when you deploy the application for creating schema or you can manually create schema without changing this)

      Second thing is make sure are you using oracle11g java-driver.

      If you changing database then no need to change in sdnext-servlet.xml.

      Please touch with us(admin@dineshonjava.com) If you will still facing these problems.
      Could you please like this site at facebook for regular updates.

      Thanks,
      Dinesh

      Delete
  29. Hi dinesh,
    You are doing great work. I tried your program and its working. Now i am using dropbox and checkbox in JSP and i need to access database from the jsp page using dropbox,checkbox. Can you show one example for the dropbox and checbox accessing the database. I am trying to enter values like employee location using dropbox, but this information is not entered in the database and it is showing empty column.

    ReplyDelete
    Replies
    1. Hi Udaykiran,

      Thanks for nice comment :)

      If you want to use dropbox as field in jsp page you have to look the following example where I have used one dropdown from database,

      http://www.dineshonjava.com/2013/05/spring-crud-example-using-one-to-one.html#.Ukzu5nxWZqc

      If you will still have a problem creating the dropbox in JSP then you can touch with us.

      Thanks,
      Dinesh

      Delete
    2. Hi Dinesh,
      I tried it but not working. When i tried to add some user credentials i am getting some errors like this.
      org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/login.jsp at line 90


      Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


      root cause

      java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
      org.springframework.web.servlet.support.BindStatus.(BindStatus.java:141)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
      org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
      org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
      org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
      org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
      org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
      org.apache.jsp.WEB_002dINF.views.login_jsp._jspx_meth_form_005flabel_005f0(login_jsp.java:267)
      org.apache.jsp.WEB_002dINF.views.login_jsp._jspx_meth_form_005fform_005f0(login_jsp.java:215)
      org.apache.jsp.WEB_002dINF.views.login_jsp._jspService(login_jsp.java:158)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

      Can you please sort out this error.
      Thanks in advance,
      Uday.

      Delete
    3. I cant understand why it is showing this error

      Delete
    4. And also for drop box and radio button mine is not working. I am using date for drop box. The data i entered is showing null. If you want i will send my code to you mail.

      Delete
    5. Hi Uday,

      Please send your application as a zip at admin@dineshonjava.com for resolving problem propery.

      Thanks,
      Dinesh

      Delete
    6. Hi Uday,

      I have looked your code of JSP found some problem in jsp form tag where your using "commandName" attribute with value "command" as follows.

      <form:form name="Login" action="/sdnext/register1.html" method="POST" commandName="command" onsubmit="return ValidateForm()">

      here "command" should be bean so that all property using in form are associated with this bean. Please look following code where we are using "employeeBean" as commandName.

      <form:form name="empForm" commandName="emoployeeBean" action="saveEmployee/">

      here employeeBean is bean associate all property of bean class with form attributes like empName, empAge. empId etc.

      Thanks,
      Dinesh

      Delete
    7. Thanks Dinesh for helping me alot. I send my WAR file to your Email-id admin@dineshonjava.com

      Delete
    8. Hi Dinesh,
      Thanks for helping me. But i need to submit my Web application by Oct 15th. Otherwise i will lose my degree. Its very urgent please solve the problem in my application. Please give me your phone number if you don't mind. I need it very urgently.

      Thanks in advance,
      Uday kiran chitturi

      Delete
    9. Hi Uday,

      I have completed your application please find attached file.
      And deploy.

      In every mail signature i have mention my contact number.

      Thanks,
      Dinesh

      Delete
  30. Hi Dinesh! Very well explained. How can i create a form when a employee may upload a picture profile.
    Thanks in advance.

    ReplyDelete
    Replies
    1. Hi,
      Thanks for nice comment.
      Please look following example where I have used file upload example.
      http://www.dineshonjava.com/2013/07/struts-2-file-upload-example.html

      Thanks,
      Dinesh Rajput

      Delete
  31. can yo exaplain annotaion and ioc.

    ReplyDelete
    Replies
    1. Hi,
      The Inversion of Control is the process by which application defines the dependency and these dependencies are then satisfied in runtime by the Spring Framework. The IoC container is the main component of the Spring framework. It provides the main IoC container and AOP framework. The core container of the Spring Framework provides important functionality including dependency injection and bean life cycle management.
      We can say that The IoC or Inversion of Control is the core features of the Spring Framework. Developers uses the IoC container to manage the beans and its dependency in the application. Thus simplifies the implementation of business logic in the application.

      for more detail have look on following.
      http://www.dineshonjava.com/2012/06/spring-ioc-container.html

      Thanks,
      Dinesh Rajput

      Delete
  32. what is the difference model clas and bean class
    employeebean and employee java

    ReplyDelete
    Replies
    1. Hi Nitin,

      Thanks for comment.

      model class and bean class both are same things but mostly we preferred to use bean class to rendering data to view file and fetching data from view file another model class we are used at back end flow like DB label.

      Thanks,
      Anamika Rajput

      Delete
    2. hi Anamika,

      can u please tell me why I am not getting the list of employees though its saving in database.

      Thanks

      Delete
  33. please explain all annotation and xml properties to understand all basic.

    i implement this project but some basics are not clear.

    ReplyDelete
  34. hi dinesh... i imported the whole project and tried executing... i am getting file not found error....

    ReplyDelete
    Replies
    1. Please update build path and redeploy again.

      Thanks,
      Dinesh

      Delete
  35. can u please help me out? 404 error????

    ReplyDelete
    Replies
    1. Hi chandana,

      You are missing to add jar files to your project.
      Please use eclipse IDE or STS IDE and Import project after that go to build path option add the all jars.

      After that you got successfully running.

      Thanks,
      Anamika

      Delete
    2. thank you so much anamika
      :) ur r8t.... now its working fine

      Delete


  36. hi Dinesh,
    Your presentation is really good.
    THanks for the infromation shared,
    Im facing one issue while running this appl,when i click on save i get 404
    message /sdnext/save.html

    as per ur above replies i understand that we need to change context in jsp files
    but im not clear what is the exact change can you please reply here so that it will be available to every one from next time.

    ReplyDelete
  37. thank you so much for this application dinesh:) u saved my life:)

    ReplyDelete
  38. is it necessary to write for every class a DAO interface,and its implementation,,,and Service interface and its implementaion.

    ReplyDelete
  39. hi dinesh ,i have to create a login page using spring MVC and hibernate plz help me out in doing this ...

    ReplyDelete
  40. Hi Dinesh plz help me. I am getting the following exception: "org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor"

    ReplyDelete
    Replies
    1. Hi Narendra,
      You are missing to add some jars file like aopalliance-1.0.jar etc. Please add these files.

      Thanks,
      Dinesh Rajput

      Delete
  41. Dinesh I am getting this error Access denied for user 'root'@'localhost' (using password: YES)

    ReplyDelete
    Replies
    1. Hi Friends,

      Please update database.properties file where we are using database username and password.
      Use password whatever you used in your machine.

      Thanks,
      Dinesh Rajput

      Delete
  42. That is better:
    CREATE TABLE Employee(
    EMPID INT NOT NULL AUTO_INCREMENT,
    EMPNAME VARCHAR(20) NOT NULL,
    EMPAGE INT NOT NULL,
    SALARY BIGINT NOT NULL,
    EMPADDRESS VARCHAR(20) NOT NULL,
    PRIMARY KEY (EMPID)
    );

    ReplyDelete
    Replies
    1. Yes ,

      comma missed befors adding primary key in Dinish code

      Delete
  43. Hi Sir,
    I am new for Spring. I used your code. I getting this error. Please help me

    20:38:36,403 INFO [STDOUT] 20:38:36,402 INFO [DefaultListableBeanFactory] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBe
    anFactory@e545fa: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,employeeController,employeeDao,employeeService,org.sp
    ringframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.spring
    framework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.co
    ntext.annotation.internalPersistenceAnnotationProcessor,jspViewResolver,dataSource,sessionFactory,hibernateTransactionManager]; root of factory hierarchy
    20:38:36,421 INFO [STDOUT] 20:38:36,417 ERROR [DispatcherServlet] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeController': Injection of autowired dependencies failed; nested
    exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dineshonjava.service.EmployeeService com.dineshonjav
    a.controller.EmployeeController.employeeService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emp
    loyeeService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field
    : private com.dineshonjava.dao.EmployeeDao com.dineshonjava.service.EmployeeServiceImpl.employeeDao; nested exception is org.springframework.beans.factory.BeanC
    reationException: Error creating bean with name 'employeeDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory
    .BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.dineshonjava.dao.EmployeeDaoImpl.sessionFactory; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/sdne
    xt-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validat
    or.ClassValidator.(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common
    .reflection.ReflectionManager)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java
    :286)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)

    ReplyDelete
    Replies
    1. Hi Ramachandran Rathinam,

      It is problem due to you are missing some jars or set up to class path of jars. So please remove all jars and add again and set to class path after that redeploy after that you will get successfully run this application with out any error.

      For more help contact at admin@dineshonjava.com.

      Thanks,
      Anamika
      sessionFactory

      Delete
  44. hi Dinesh,
    i got following errror at the time server starting.
    SEVERE: StandardWrapper.Throwable
    org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [resources/database.properties] cannot be opened because it does not exist
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:640)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:615)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)

    ReplyDelete
    Replies
    1. Hi friend,

      you are missing to add "resources/database.properties" file to your application please add this and run server.
      After that redeploy after that you will get successfully run this application with out any error.

      Thanks,
      Anamika

      Delete
  45. I configured database.properties locataion correctly but still got same problem.

    ReplyDelete
    Replies
    1. You have to add this file to classpath also.

      Delete
  46. Thanks very much Dinesh. Your example is really simple and elegant.

    ReplyDelete
    Replies
    1. Your welcome Naval and thanks for learning with us.

      Thanks,
      Dinesh

      Delete
  47. Hi Dinesh,

    When I am trying to save in database its saving but i am not able to get the list employees,again add employee fields are comming.

    Please give me some feedback.

    Thanks,
    Rajendra

    ReplyDelete
    Replies
    1. Please check in code you missing some logic of display. Please match with tutorial.

      Thanks,
      Anamika

      Delete
  48. Replies
    1. Thanks Akash for nice comment.

      Thanks,
      Dinesh

      Delete
  49. Hello Dinesh,
    Thanks for your efforts in sharing your knowledge in Spring.
    I ve downloaded your application and did all the necessary setup in my local machine.
    Its working fine. But when i change the context root and spring xml name the code is not compiling.
    The code always look for the classes you given.
    I ve tried changing the context root, and other setting advised throughout the discussions.
    But not able to succeed in running this code with different context root or different spring xml name.
    Pls look into the code and help me to run the code.

    Kind Regards,
    Nathan

    ReplyDelete
    Replies
    1. Hi,
      Which IDE you have used for this application?

      Delete
    2. Thanks for the prompt response. Much appreciated. PFB for details.

      IDE:eclipse-EE-kepler-win32
      JAVA:1.7
      Apache Tomcat:7
      I am using . I am sending the zip file pls check that and let me know why i am not able to compile whenever i make some changes.

      Kind Regards,
      Nathan.

      Delete
  50. I ve sent my code to admin@dineshonjava.com from britoamal@gmail.com.
    Tomcat log shows error like below but in the lib folder icu4j-2.6.1.jar is already there and i am using all the jars provided in your example. It seems this application is not compiling. Pls reply asap

    Regards,
    Nathan

    ------
    Unable to process Jar entry [com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class] from Jar [jar:file:/F:/Eclipse%20Kepler/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SpringHiberD/WEB-INF/lib/icu4j-2.6.1.jar!/] for annotations
    -----------------

    ReplyDelete
  51. HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not insert: [com.dineshonjava.model.Employee]

    java.sql.SQLException: Field 'ADDRESS' doesn't have a default value


    PLEASE help me on this

    ReplyDelete
  52. Hi Dinesh, when i am connecting from server .. i get the same problem Null Pointer Exception... so let me know which type of Excepton is coming...

    ReplyDelete
  53. Hi Dinesh i am new to spring . my doubt is in the above example link add.html we have given but add.html is not there then how it goes to addEmployee.jsp page

    ReplyDelete
  54. Hi Dinesh, u r using static here cannot we use delete operation dynamically with out a query.. if possible please let me know
    public void deleteEmployee(Employee employee) {
    sessionFactory.getCurrentSession().createQuery("DELETE FROM Employee WHERE empid = "+employee.getEmpId()).executeUpdate();
    }

    ReplyDelete
  55. Hi dinesh,
    org.apache.catalina.core.StandardContext listenerStart
    SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dineshonjava.service.EmployeeService com.dineshonjava.controller.EmployeeController.employeeService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dineshonjava.dao.EmployeeDao com.dineshonjava.service.EmployeeServiceImpl.employeeDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.dineshonjava.dao.EmployeeDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/sdnext-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(Standar

    ReplyDelete
  56. And
    Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getDeclaredConstructors(Unknown Source)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:228)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:911)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:884)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1308)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
    ... 65 more
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.KeyedObjectPoolFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 82 more

    ReplyDelete
  57. Hi, may I know what exactly, I need to change / update the "context root(sdnext)" as per as my application configuration in jsp files. so that my application will be successfully running.

    ReplyDelete
  58. I have already change the - as per my package. but still i have the same error code of 404. (HTTP Status 404 - /sdnext/save.html). (My controller class is not getting invoked)

    ReplyDelete
  59. Hi dinesh,
    can you please post the same application using JDBC instead Hibernate

    ReplyDelete
  60. This comment has been removed by the author.

    ReplyDelete
  61. This comment has been removed by the author.

    ReplyDelete
  62. Hi Dinesh,
    I am getting following error when i am trying to add new employee.

    message Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    root cause

    org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
    org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
    org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
    org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
    org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
    org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
    org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:412)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    com.sun.proxy.$Proxy31.addEmployee(Unknown Source)
    com.dineshonjava.controller.EmployeeController.saveEmployee(EmployeeController.java:34)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:606)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

    ReplyDelete
  63. ramework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/annotations/Entity
    at org.springframework.beans.factory.suppor
    Servlet /springhibernate threw load() exception
    java.lang.ClassNotFoundException: org.hibernate.annotations.Entity




    ReplyDelete
  64. hi dinesh

    these much error came ,,,how solve this ,
    please help me ,

    ReplyDelete
  65. Thank you so much Dinesh, your code just work..excellent job keep it up

    ReplyDelete
  66. Hi, dinesh.
    I have import your project into my Eclipse Workspace,
    I have change the database properties : without password :
    ===========================================
    database.driver=com.mysql.jdbc.Driver
    database.url=jdbc:mysql://localhost:3306/db_employee
    database.user=root
    database.password=
    hibernate.dialect=org.hibernate.dialect.MySQLDialect
    hibernate.show_sql=true
    hibernate.hbm2ddl.auto=update
    ===========================================
    But when I run the project into the server I have this problem:
    HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection

    exception

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


    What's the problem ?
    Could you give me the answer ?

    Thanks

    ReplyDelete
    Replies
    1. Hi,

      Please use the following code in sdnext-servlet.xml


      <bean id="sessionFactory" > class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
      <prop key="hibernate.show_sql"> true</prop>
      <prop key="hibernate.hbm2ddl.auto"> create</prop>
      </props>
      </property>
      <property name="packagesToScan" value="com.entity"> </property>
      <property name="annotatedClasses">
      <list>
      <value> entity.Student</value>
      </list>
      </property>
      </bean>

      Here we avoid to use database.properties file.

      Please try this.

      Thanks,
      Dinesh

      Delete
  67. hello sir, I get error "add.html" is not found. Where is that file. Please tell me as soon as possible.

    Thanks.

    ReplyDelete
  68. hi Dinesh

    this is rajasekhar iam getting this error

    Feb 21, 2014 3:34:38 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [sdnext] in context with path [/sdnext] threw exception [Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection] with root cause
    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:868)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3340)
    tanks
    rajasekar
    9966445400

    ReplyDelete
    Replies
    1. <bean id="sessionFactory" > class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
      <prop key="hibernate.show_sql"> true</prop>
      <prop key="hibernate.hbm2ddl.auto"> create</prop>
      </props>
      </property>
      <property name="packagesToScan" value="com.entity"> </property>
      <property name="annotatedClasses">
      <list>
      <value> entity.Student</value>
      </list>
      </property>
      </bean>

      Here we avoid to use database.properties file.

      Please try this.

      Delete
    2. i have done it. by see the above code

      thanks you so much

      for further details i will contact

      thanks
      rajasekhar

      Delete
  69. Hi Dinesh , its a wonderful tutorial, can u tell me how to the same things when the employee table will have link with department table with a primary table, i mean how both the table values will be updated?

    ReplyDelete