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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:15:45+00:00 2026-06-10T09:15:45+00:00

To save entity with doctrine I should do like this $em = $this->getDoctrine()->getEntityManager(); $em->persist($product);

  • 0

To save entity with doctrine I should do like this

$em = $this->getDoctrine()->getEntityManager();
$em->persist($product);
$em->flush();

But maybe I can somehow do that in one line like

$product->save();

or

$this->saveEntity($product);

or

$this->getDoctrineEntityManager()->persistAndFlush($product);

If I need to create this methods by my self then how to do that in symfony way?

  • 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-10T09:15:46+00:00Added an answer on June 10, 2026 at 9:15 am

    Well persist() and flush() are totally different and independent operation. When you persist an entity object you are telling the entity manager to track changes of the object. When you call flush() method the entity manager will push the changes of the entity objects the entity manager tracks to the database in single transaction. Most of the time entity manager have to manage multiple object. For example besides your product entity you may also have to track tag or cart entity. Calling persistAndFlush() every time when you save those entity object will cause multiple IO connection to DB. Which is not efficient. So I think it is better to treat them as a separate operation.

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

Sidebar

Related Questions

I want to save one of my entity objects into the session, but as
Suppose you have a method: public void Save(Entity data) { this.repositoryIocInstance.EntitySave(data); } Would you
Having this Entity for example: <?php namespace Gitek\HotelBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** *
This is my AbstractNHibernateDao, i'd like to use SaveOrUpdateCopy with Merge command, but when
Firstly, this question is similar to How to re-save the entity as another row
Let's say I have an entity called Product and this entity is loaded every
If I save an entity using a Hibernate session, and then probe to get
I am using Google App Engine with Google's JDO implementation to save an entity
When I do a save of an entity with assigned id I get a
Let's say I create a new Entity and Save it as follows: UserReport report

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.