18 January 2009

Seam JPA - Manual Flush

In Seam, (only) when using Hibernate as the underlying JPA implementation, we have the option of flushing manually to the database. One possible scenario where we may apply this is during batch update, as we may not want to accumulate and push all DB update till the end.

Below is an example, how to configure it using annotation
@Begin(join=true,flushMode=FlushModeType.MANUAL)
public void methodWhereSomeThingStarts() {


and in the method that ends the conversation, we can use

@End
public void methodWhereBatchUpdateAndConversationCanEnd() {
//Iterating loop
em.flush();

Note: em is javax.persistence.EntityManager