title: JSON sent over AJAX to Spring+Hibernate based application does not get persisted
body: <p>I am sending JSON object to a Spring+Hibernate+MySQL application. </p>
  
  <p>Bellow is <code>index.html</code> where you can see the javascript making the request. Then there is <code>Customer.java</code> entity and <code>CustomerRestController.java</code> responsible for the request processing. Somehow my database is not getting updated.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;    
  &lt;head&gt;    
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;  
  &lt;script type="text/javascript"&gt;
       $(document).ready(function(){           
           $('#btnBooking').click(function(){  
                   var custName=$('#userName').val();              
                   var custAddress=$('#address1').val();  
                   var JSONObject= {"name":custName, "address":custAddress};
                   //var jsonData = JSON.stringify( JSONObject );
                   $.ajax({
                       type: "POST",
                       url: "http://192.168.1.12:8080/HomeServiceProvider/rest/customer/saveCustomer",            
                       data: JSON.stringify( JSONObject ),
                       dataType: "json",
                       processData: true,
                       contentType: "application/json; charset=utf-8",
                       success: function(data, status, jqXHR){
                          alert("success..."+data);
                       },
                       error: function(xhr){
                          alert("error"+xhr.responseText);
                       }
                  });     
           });  
      }); 
  &lt;/script&gt;
  &lt;/head&gt;
      &lt;body&gt;          
          &lt;form class="form-horizontal" id="scheduleLaterForm" name="scheduleLaterForm" action="#" method="post"&gt;
              &lt;div class="col-lg-8"&gt;                                      
                  &lt;div class="form-group"&gt;
                      &lt;label class="col-lg-3 control-label"&gt;Name:&lt;font style="color: red;"&gt;*&lt;/font&gt;&lt;/label&gt;
                      &lt;div class="col-lg-9"&gt;
                          &lt;input class="form-control" id="userName" name="userName" placeholder="Full Name" value="" type="text"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                      &lt;label class="col-lg-3 control-label"&gt;Address:&lt;font style="color: red;"&gt;*&lt;/font&gt;&lt;/label&gt;
                      &lt;div class="col-lg-9"&gt;
                          &lt;input class="form-control" name="address1" id="address1" placeholder="Full address" value="" type="text"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group marg-bot-45"&gt;
                      &lt;label class="col-lg-3 control-label"&gt;&lt;/label&gt;
                      &lt;div class="col-lg-9"&gt;
  
                          &lt;button type="button" class="btn btn-info" id="btnBooking"&gt; Confirm Booking &lt;/button&gt;                                               
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;              
          &lt;/form&gt;                     
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Customer.java</p>
  
  <pre><code>@Entity
  @Table(name="CUSTOMER")
  public class Customer implements Serializable{
  
      private static final long serialVersionUID = -82689141527424144L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column (name="CUST_ID")
      private int custId;
      @Column (name="NAME")
      private String name;
      @Column (name="ADDRESS")
      private String address;
  
      public int getCustId() {
          return custId;
      }
      public void setCustId(int custId) {
          this.custId = custId;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public String getAddress() {
          return address;
      }
      public void setAddress(String address) {
          this.address = address;
      }
  }
  </code></pre>
  
  <p><strong>CustomerRestController.java</strong></p>
  
  <pre><code>@RestController
  @RequestMapping("/customer")
  public class CustomerRestController {
  
      private static Logger log = LogManager.getLogger(CustomerRestController.class);
  
      @Value("${msg.customeradded}")
      private String message;
      @Value("${msg.successcode}")
      private int code;
  
      @Autowired
      private CustomerService customerService;
  
      @RequestMapping(value = "/saveCustomer", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
      public @ResponseBody Status saveCustomer(@RequestBody Customer customer){
          try {
              customerService.saveCustomer(customer);
              return new Status(code, message);
          } catch (Exception e) {
              return new Status(0, e.toString());
          }
      }
  
      @RequestMapping(value="/getAllCustomer",method=RequestMethod.GET, headers="Accept=application/json")
      public @ResponseBody List&lt;Customer&gt; getAllCustomer(){
          List&lt;Customer&gt; customers = null;
          try {
              customers = customerService.getAllCustomer();
          log.info("Size:"+customers.size());
          log.info("customers:"+customers);
          } catch(Exception e) {
              e.printStackTrace();
          }
          return customers;
      }
  }
  </code></pre>
  
  <p><strong>CustomerService.java</strong></p>
  
  <pre><code>public interface CustomerService {
  
      public void saveCustomer(Customer customer);
      public List&lt;Customer&gt; getAllCustomer();
  
  }
  </code></pre>
  
  <p><strong>CustomerServiceImpl.java</strong></p>
  
  <pre><code>@Service
  public class CustomerServiceImpl implements CustomerService {
  
      private static Logger log = LogManager.getLogger(CustomerServiceImpl.class);
  
      @Autowired
      private CustomerDao customerDao;
  
      public void saveCustomer(Customer customer) {
          log.info("customer first name:" + customer.getCustName());
          customerDao.saveCustomer(customer);
      }
      public List&lt;Customer&gt; getAllCustomer() {
          List&lt;Customer&gt; customers = customerDao.getAllCustomer();
          log.info("Size:"+customers.size());
          log.info("customers:"+customers);
          return customers;
      }
  }
  
  
  Name of My table is CUSTOMER and columns are
  </code></pre>
  
  <p>colomn1: CUST_ID<br>
  colomn2: NAME<br>
  colomn3: ADDRESS </p>