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

  • Home
  • SEARCH
  • 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 7814777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:18:11+00:00 2026-06-02T05:18:11+00:00

I am using Spring 3 and Hibernate 4 to build my project. My question

  • 0

I am using Spring 3 and Hibernate 4 to build my project.

My question is that for example, a User object has five fields, id, name, password, school and address. I only give the user the right to update/edit his school and/or address. When the user first access the edit page via GET,I want to populate the field with the user’s existing information.

Once submit button is clicked, I want to change the corresponding updated fields in my database via hibernate.

Controller.java

@RequestMapping(value="/edit/{userId}", method="RequestMethod.GET")
public String toEdit(Model model,@PathVariable int userId){
    User user = userService.get(userId);
    model.addAttribute("command",user);
    return "/edit";
}

@RequestMapping(value="/save", method="RequestMethod.POST")
public String toSave(Model model){
    //how to implement this?
}

edit.jsp

<form:form action="/save" method="POST">
    <form:input path="school"/>
    <form:input path="address"/>
    <input type="submit"/>
</form:form>

My thought is that if I can put those fields that are not updated as hidden field in the edit.jsp page so that when the User object rebinds(when the form is submitted), I could still capture the user’s id, name and password information.

The pitfall of my approach is obvious. First, password as hidden field is never the way to go. Second, it adds unnecessary information on the edit.jsp page.

My second thought is that I could only put the user id as hidden field in the edit.jsp and when the form is submitted, I could use User user = userService.get(command.id) to get the corresponding user object and set the fields (e.g. school or address) to those newly entered ones by something like user.setSchool(command.getSchool()). After all of these, I can update the user object. This approach is kinda of troublesome, because if I got a lot of fields to update, there is gonna be a lot of code.

Is there a better way to do this? (I am sure there must be one) I am very new to Spring and Hibernate, so if I am missing something very obvious, please let me know.

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-06-02T05:18:14+00:00Added an answer on June 2, 2026 at 5:18 am

    If you use “dynamic-update” only modified fields will be updated.
    You may ues the @org.hibernate.annotations.Entity to mark your entity for dynamic updates.

    @Entity
    @org.hibernate.annotations.Entity(
            selectBeforeUpdate = true,
            dynamicInsert = true, dynamicUpdate = true)
    public class User { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a web application using Spring/Hibernate that displays a report to a user,
I'm trying to build a spring roo project using hibernate and an oracle database.
I am using Spring with Hibernate in my project.There are many methods written in
I am creating a project using maven with spring and hibernate. I added a
I want to build an application using Hibernate and MyBatis integrate with Spring. In
I have a Spring project using Hibernate. The DB is generated based on the
I am using Hibernate with spring. I have a model-class like this. @Entity @Table(name
I have a simple spring3,hibernate 3 project.When am trying to build the project using
I am using spring/hibernate. i have configured 5 datasources in applicationContext.xml file. All datasources
We're using Spring/Hibernate on a Websphere Application Server for AIX. On my Windows machine,

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.