Results 1 to 10 of 21

Thread: How to update entity partially

Hybrid View

  1. #1

    Default How to update entity partially

    Hi,

    I have an entity Userinfo having many fields. Some are with NotNull and some allows null value.

    Method Signature:

    @RequestMapping(value = "/userinfo/{id}/update", method = RequestMethod.POST)
    public String updateintercept(@Valid Userinfo userinfo, BindingResult result, ModelMap modelMap,HttpServletRequest request) {
    ...........
    }

    Entity: Userinfo
    Fields:

    userid(NotNull ),
    password(NotNull ),
    emailId(NotNull ),
    phone,
    enable(NotNull ),
    creattionDate(NotNull ),
    updationDate(NotNull )

    Now I want to update selected fields like email, phone, enable.
    I don't want to populate those fields into the form which are not getting updated.
    result.hasErrors() method returning true.

    Please suggest me the required changes in my code.

    Thanks & regards,
    Punit Kumar Dwivedi

  2. #2
    Join Date
    Dec 2007
    Location
    Stockholm, Sweden
    Posts
    190

    Default

    I assume you dont want to update the creation date in this case,

    You can use JPA @Column(updatable = false)

    I have a similar setup which uses a BaseEntity with userWhoCreatedd/timeCreated , userWhomodified/Timemodified updated with Aspects,
    Shahzada Hatim
    @geoaxis/twitter
    http://hatimonline.com

  3. #3
    Join Date
    Jan 2008
    Posts
    18

    Default

    I have similar problem, but JPA with 'updatable' is not what I want. I have form that need to update only one field i.e. 'phone' (I don't want to populate in the page all fields like 'password', 'enable', ...).

  4. #4

    Default

    Hi entaroadun7,

    You should user following annotation for password, enable.
    @Column(updatable=false)

  5. #5
    Join Date
    Jan 2008
    Posts
    18

    Default

    Hi,

    I can't use 'updatable=false' because I have other forms where I allow to change password and enable.

  6. #6
    Join Date
    Dec 2007
    Location
    Stockholm, Sweden
    Posts
    190

    Default

    Well in that case you will need to have to write a custom form, controller and validator.

    You can probably reuse the form and controller with some if statements but the controller uses imlicit validator for your entity in ROO.
    Shahzada Hatim
    @geoaxis/twitter
    http://hatimonline.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •