Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda