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 7532411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:26:42+00:00 2026-05-30T05:26:42+00:00

In the api doc for play.db.jpa.Model ,the description for the method refresh() is given

  • 0

In the api doc for play.db.jpa.Model ,the description for the method refresh() is given as ‘Refresh the entity state.‘..

In the documentation for jpa,the following snippet is given

public static void save(Long id) {
    User user = User.findById(id);
    user.edit("user", params.all());
    validation.valid(user);
    if(validation.hasErrors()) {
        // Here we have to explicitly discard the user modifications...
        user.refresh();
        edit(id);
    }
    show(id);
}

In the paragraph above,it is given

we must tell the EntityManager which Objects NOT to update. We do this
by calling refresh(), which essentially rolls back a single entity. We
do this just prior to calling commit on the transaction or when we
realise the Object shouldn’t be updated.

Reading the api doc for the method ,I came to understand that by calling refresh(), the model state will be set to what was in the database.

But reading those snippet/paragraph ,I am getting confused..

Can someone please tell me what refresh() does?

I coded an app like,

...
Order lastOdr = Order.find("some query to find the last pending order..").first();
if(lastOdr!=null) {
   lastOdr.refresh();
}
...

Is this wrong?I am trying to get the Order object from the database by executing that query..

  • 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-30T05:26:43+00:00Added an answer on May 30, 2026 at 5:26 am

    In that code snippet:

    user.edit("user", params.all());
    

    will populate the entity with http request parameters which name start with “user”, say if the request has a parameter called “user.firstName”, then that value will be used to populate the user model’s firstName field.

    user.refresh();
    

    is called when validation.hasErrors(), meaning it will use the current database values to refill the user model and discard all changes coming form user.edit("user", params.all());. However I don’t think this statement is needed because Play will not commit the changes unless you explicitly call user.save().

    There is no need to call refresh() in your code, as you have just fetch it from database, the state is supposed to be the same as it is in the database

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

Sidebar

Related Questions

according to the twitter api documentation http://dev.twitter.com/doc/get/statuses/user_timeline accessing the current logged in users timeline
QtCreator has this nice feature to bring up the API-doc for a class/method when
I used to looking up classes/methods from Help->Developer Documentation, which has API doc in
In the JMS API doc, it said: public Message receive() throws JMSException Receives the
I'm trying to read the cocos2d api doc but I'm confused about what the
i just got an account at: http://www.whoisxmlapi.com/index.php#/whois-api-doc.php?rid=1 ive never parsed XML with c#, how
I am trying to POST an image to imageshack using their API and Play
So taking a look at the API doc page here: http://developers.facebook.com/docs/reference/javascript/FB.api I'm wondering if
The Spring Framework API doc says: The convention used is to return the uncapitalized
I'm using the autocomplete jQuery plugin ( api doc ) that calls a service

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.