java - What does EntityManager.flush do and why do I need to use it? -


i have ejb saving object database. in example have seen, once data saved (entitymanager.persist) there call entitymanager.flush(); why need this? object saving not attached , not used later in method. in fact, once saved method returns , expect resources released. (the example code on remove call well.)

    if (somecondition)         entitymanager.persist(unattachedentity);     else     {         attachedentityobject.setid(unattachedentity.getid());     }     entitymanager.flush(); 

a call entitymanager.flush(); force data persist in database entitymanager.persist() not (depending on how entitymanager configured : flushmodetype (auto or commit) default it's set auto , flush done automatically if it's set commit persitence of data underlying database delayed when transaction commited).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -