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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:12:02+00:00 2026-05-13T15:12:02+00:00

In my code, I did as follows: queried for a course entity populate it

  • 0

In my code, I did as follows:

  • queried for a course entity
  • populate it with the given course data.
  • courseDao.update(entity) which internally calls persist(entity) method.
  • Surprisingly, the data is got updated successfully.

I am confused with this behaviour of persist method.

Please help me out.

code is as below:

//My Service......
@Service("myService")
@Transactional
public class MyServiceImpl implements MyService {

  @Transactional(rollbackFor = { Throwable.class })
  public void updateCourse(final Course course) throws MyServiceException {
    ------
    ------
    CourseEntity courseEntity = courseDao.findById(course.getId());
    populateCourseEntity(courseEntity, course);

    courseDao.update(courseEntity);
  }
}

//CourseDao.....

public class CourseDaoImpl implements CourseDao {
   --------
   public void update(final T entity) throws MyDaoException {
        if (entity != null) {
            this.entityManager.persist(entity);
        }
        else {
            String errMsg = "Object to be updated cannot be null.";
            throw new MyDaoException(errMsg);
        }
    }
}
  • 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-13T15:12:03+00:00Added an answer on May 13, 2026 at 3:12 pm

    When an entity is currently managed (attached to a session), all updates to it are directly reflected to the underlying storage even without calling persist().

    In your case, you load your entity, so it’s in the session. Then even if you don’t call persist() it will be updated in the database on transaction commit.

    The persist() description from the javadoc:

    Make an entity instance managed and persistent.

    This means that the method doesn’t do anything in your case, since your entity is both persistent and managed.

    P.S. Where I say “session”, understand “entity manager”

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

Sidebar

Related Questions

I recently wrote a piece of code which did SomeClass someObject; mysqlpp::StoreQueryResult result =
I have some code which I did not originally create that uses _beginthreadex and
The main problem is as follows: I did my code in console application and
HI i did this code with help of Marc Gravell in Why can't I
Did you ever had a bug in your code, you could not resolve? I
What did I do wrong? Here is an excerpt from my code: public void
I'm code reviewing a change one of my co-workers just did, and he added
I lost the source code from one project I did on the company I'm
I was looking over this code to calculate math.sqrt in Java. Why did they
When I've worked a bit with my source code, I did my usual thing

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.