Transaction timing out

I have a problem with transaction timing out and I know how to increase the time out interval but I would just like to learn as to what exactly is going on and how I can fix the problem without increasing the timeout.

class RequestProcessor {

public void do() {

// very long process

doSomeWhereLongProcess()

.....

// retrieve another session bean

persistence = (IPersistence) ctx.lookup( IPersistence.JNDI_NAME );

persistence.insert()

.....

doSomeProcess();

}

}

public class PersistenceFacade implements IPersistence {

@PersistenceContext

private EntityManager em;

// calls an entityManager to retrieve

public void retrieve()

}

RequestProcessor is a session bean that is being called remotely. In ejb-jar.xml transaction type is set to Bean.

It calls another session bean called PeristenceFacade that contains entity manager to insert entity beans. The transaction type in PersistenceFace

is set to Container.

While still executing a doSomeWhereLongProcess I get notification in log that transaction timed out and when it tries to called PersistenceFacade

I get an exception. Why would it start a transaction even before I looked up a PersistenceFacade?

I tried setting transaction type to Bean in PersistenceFacade but it is complaining that EntityManager must have a transaction.

What is the proper way of handling this type of scenario? Is is simply increasing the timeout or can I handle this differently?

Thanks

[1581 byte] By [fkzeljoa] at [2007-10-3 3:35:19]
# 1
Where is the transaction that is timing out being started?Is it a UserTransaction started within RequestProcessor.doSomeWhereLongProcess?
ksaksa at 2007-7-14 21:30:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Hi thanks for your help,That is what I am trying to figure is how is the transaction being started. That method doSomeWhereLongProcess just calls an external process (batch script) so it has nothing to do with transaction.
fkzeljoa at 2007-7-14 21:30:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

You should double-check that the initial bean does indeed have bean-managed transactions. One possibility is that it has container-managed transactions and the container is starting a transaction when the method is entered.Otherwise, if you're not starting a transaction, then it must be started somewhere else.When are you getting the tx timeout ? Typically this happens when an attempt is made to commit the transaction.Please include the stack trace from the server.log.

--ken

ksaksa at 2007-7-14 21:30:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Ok Ksaks thanks again for your help.

I am novice when it comes to ejb so here are few of my questions.

In my ejb-jar.xml I specifed that the RequestProcessor session bean should have bean managed transaction. Howerver in the actual bean I didn't look up the UserTransaction nor did I start the transaction or comitted. Essentially I wanted a bean without transaction support right now. Is it enough just to specify in ejb-jar that transaction should be bean managed. Do I actually need to manually start a transaction and commit it?

It seems that my bean gets the container managed transaction. The transaction starts as soon as the RequestProcessor session bean calls the @PostConstruct method in the interceptor.

The following is a print out in the JBOSS log when the transaction times out while I am still in the RequestProcessor session bean doing some trivial long action.

2006-08-28 10:36:45,828 WARN [org.jboss.tm.TransactionImpl] Transaction TransactionImpl:XidImpl[FormatId=257, GlobalId=AGS0191/18, BranchQual=, localId=18] timed out. status=STATUS_ACTIVE

The trivial method call ends and I look up another session bean "PersistenceFacade" that contains the entity manager and performs a retrieve. The following is part of the stack trace

2006-08-28 10:49:31,593 DEBUG [org.hibernate.util.JDBCExceptionReporter] Cannot open connection [?]

org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=AGS0191/18, BranchQual=, localId=18]; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=AGS0191/18, BranchQual=, localId=18])

at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94)

at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)

at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)

at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)

at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)

at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)

at org.hibernate.loader.Loader.doQuery(Loader.java:661)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)

at org.hibernate.loader.Loader.doList(Loader.java:2145)

at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)

at org.hibernate.loader.Loader.list(Loader.java:2024)

at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:392)

You said I should double-check that initial bean does indeed have bean-managed transaction. How do I check that? Is it possible to check it programatically while the server is running or before it is deployed?

fkzeljoa at 2007-7-14 21:30:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Yes, it's perfectly legal to define a bean with bean-managed transaction management that doesn't actually start a transaction.In that case, the question is where the transaction is getting started.Even for beans with container-managed transactions, @PostContruct for a session bean is never a transactional method, so it seems odd that a new transaction would be started there unless some piece of application code is starting it.

You might want to post to a JBoss forum to get more info.You can try running your application on the Java EE SDK or using the verifier in the Java EE SDK to see if it detects any issues.

--ken

ksaksa at 2007-7-14 21:30:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...