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
Post a Comment