AFP_555 AFP_555 - 4 days ago 6
Java Question

When are transactions commited with JEE JPA (EclipseLink 2.0)?

When are transactions committed with JPA (EclipseLink 2.0)?

This is my problem:

public void methodA()
{
while(something)
{
methodB();
}
}

public void methodB()
{
//Insert new client into Client table.
}


Let's say it takes 10 minutes for
methodA
to be completed. If I peek the database's Client table while
methodA
runs, I can't see any row. This means after
methodB
ends, the transaction is not committed. But if I wait until
methodA
finishes, then the clients appear in the database.

I want every transaction to be committed after
methodB
ends. How can I do this?

EDIT: I want the application container (Glassfish) to take care of the "commit". I don't want to do this by calling the Entity Manager. I'm looking for something such as an annotation above
methodB()
. Both methods are inside a singleton bean.

Answer

With @Stateless EJB beans, transaction is commited when leaving EJB (by default).

Put methodB() in separate EJB.(assuming methodA() is not EJB)

Comments