Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
How will the below code get executed internally in JPA?
entityManager.getTransaction.begin();

Employee emp = new Employee();

emp.setName("Abc");

emp.setCity("Pune");

entityManager.persist(emp);

emp.setName("Xyz");

entityManager.getTransaction.commit();

I know it'll update the name but how does it internally work? Like what will be the flow and what will be the effect on DB when entityManager.persist(emp); is executed and entityManager.getTransaction.commit(); is executed?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

When you call the entityManager.persist(emp);, the entity is not physically persisted in the database. It is being managed from that point by the Persistence Provider.

When you call entityManager.getTransaction.commit();, this is where the actual physical insert of the persisted entity is generated.

You can tell the persistent provider to perform the insert into the database before the transaction is commited by invoking the entityManager.flush() which basically synchronizes the context with the database. You have to remember though that this will not commit the transaction, so that data could still be rolled back.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda