Entitymanager.flush() VS EntityManager.getTransaction().commit - What should I prefer?

前端 未结 5 683
我在风中等你
我在风中等你 2020-12-08 00:37

What should I prefer when updating the database? What are the pros & cons with either method and when shall I use the one or the other?

public void disem         


        
5条回答
  •  暖寄归人
    2020-12-08 00:57

    You did read the javadoc for flush and commit and know that flush is only for use within a transaction? It flushes (but doesn't commit), whereas commit commits data (obviously). They are distinct; there is no "preference" to be had. The first example is wrong, and should result in an exception on calling flush (TransactionRequiredException)

提交回复
热议问题