Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6741749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:45:45+00:00 2026-05-26T11:45:45+00:00

I have a Spring Hibernate MVC and trying to implement CRUD operations. I have

  • 0

I have a Spring Hibernate MVC and trying to implement CRUD operations. I have gotten create, get, delete in a “RESTful” kinda way but I am having difficulties with update.

When trying to update the object, the parameter is /id?form, the controller code for that is:

@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
    public String updateForm(@PathVariable("id") Long id, Model uiModel) {
        uiModel.addAttribute("invoice", invoiceServiceHibernate.getInvoice(id));
        return "invoices/update";
    }

So, the JSP form for update gets filled with the object, using the id. The JSP update form is as follows:

<c:if  test="${!empty invoice}">
<form:form method="PUT" commandName="invoice">
    <table>
        <tr>
            <td>Amount</td>
            <td><form:input value="${invoice.amount}" path="amount" /></td>
        </tr>
        ... more labels and fields ...
        <tr>
            <td colspan="3">
                <input type="submit" value="Update Invoice" />
            </td>
        </tr>
    </table>
</form:form>

Upon submit, the controller method that gets called should be:

@RequestMapping(method = RequestMethod.PUT)
    public String update(Invoice invoice, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
        if (bindingResult.hasErrors()) {
            uiModel.addAttribute("invoice", invoice);
            return "invoices/update";
        }
        uiModel.asMap().clear();
        invoiceServiceHibernate.updateInvoice(invoice);
        return "redirect:/invoices/";
    }

I have tried the hibernate method update, saveOrUpdate, and merge invoiceServiceHibernate.updateInvoice(invoice) and it does not work.

The controller ends up creating a new invoice instead of updating the old one. Does anyone why that is the case? I was reading up on this link and it talks about using @ModelAttribute. I’ve tried it but it still does not work. Using @ModelAttribute or @Valid does nothing. The app does not create a new invoice but it does not update the current invoice.

Any suggestions?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:45:46+00:00Added an answer on May 26, 2026 at 11:45 am

    Where’s the ID in your JSP? It looks like you’re not sending back invoice.id as part of your form.

    Hibernate doesn’t have any way to figure out which invoice it’s supposed to update if the id isn’t included somehow in the incoming request. The basic function of Spring’s WebDataBinder isn’t really as magic as it seems. All it does is make a new object (or use an existing one if it exists in the ModelMap) then string-match request parameters against bean setter names and call the setters. (There is of course some magic happening for type conversion and so forth.) If there’s no ID in the request parameters, the ID field of your Entity will be blank when the WebDataBinder makes a new one. You need a way to provide the ID to the databinder.

    There are two basic ways you can accomplish this.

    First you can bind every field that’s part of the Entity in your form. You’d have a hidden field for invoice.id, invoice.version, etc etc.

    Second you can keep a copy of the Entity around in memory on the server. This of course introduces server side state, so isn’t exactly RESTful. You could use Spring’s @SessionAttributes on your controller to tell it to keep the Entity in memory and have the databinder update it with the new values, instead of creating a new one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone outline the steps required to get hibernate working with spring mvc. I've
I have a spring mvc project and am trying to test out a rest
I am using Spring MVC 2.5, and I am trying to get a JSTL
Firstly anyone else trying to get onto forum.hibernate.org. I have been trying for a
I have Spring MVC App integrated with Hibernate. Everything was OK until I use
I'm trying to use hibernate with spring 3 mvc but at the moment I
I have been learning java spring hibernate MVC for 3 months and got pretty
I am learning spring mvc and hibernate. i have just finished simple site with
I am using Hibernate in Spring MVC 3.05 and an Oracle database. I have
I have a Spring MVC based Web Application with Hibernate. Following is the directory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.