« Return to Thread: Inserts and Caching

Re: Inserts and Caching

by Gordon Yorke-2 :: Rate this Message:

Reply to Author | View in Thread

Jan,
   Assuming that these operations occur within a single JTA or
application managed transaction you should use the following pattern.

->begin operations - transaction alpha active<-
    //operate on em
    while (?){
      em.persist(); // or whatever else needs to happen
    }
    //operation complete
   em.flush(); // flush changes to database within current transaction
   em.clear(); //clear the em (including em cache) of all managed
entities (you may not always need this)
->end operation - transaction alpha still active <-

as long as the same transaction is active for all of the operations if
anything fails a rollback of the transaction will revert all of the SQL
EclipseLink sent to the database within that transaction from all of the
previous flush operations.  On rollback the EntityManager will be
cleared and your application will have a clean slate.  The old entities
that were previously associated with this EM will now be detached and
are in a state where they may have uncommitted changes.  Some
applications can use these detached instances to retry the transaction
with EM.merge() other applications will throw them away and start from
scratch.

--Gordon

ossaert wrote:

> Anyway, I still have the problem why the Insert over the API does not
> work....
>
> Can somebody help?
>
> Thanks
> Jan
>
>
>  
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

 « Return to Thread: Inserts and Caching