JPA flush vs commit

前端 未结 3 2093
北海茫月
北海茫月 2020-12-20 17:19

in JPA, if we call EntityTransaction.commit(), does it automatically call EntityManager.flush()? or should we call them both? what is the difference? because i have problem

3条回答
  •  既然无缘
    2020-12-20 17:49

    em.flush() - It saves the entity immediately to the database with in a transaction to be used further and it can be rolled back.

    em.getTransaction().commit - It marks the end of transaction and saves all the chnages with in the transaction into the database and it can't be rolled back.

    Refer https://prismoskills.appspot.com/lessons/Hibernate/Chapter_14_-_Flush_vs_Commit.jsp

提交回复
热议问题