I wonder if anyone can please provide some assistance with an explanation of asynchronous activity and transactions.
We are attempting to write a variety of cron functions to be executed in seam. We are using the quartz scheduler. Some of these crons may run for 30 minutes to an hour. Often they need to iterate over many items in the database (perhaps 10,000 to 100,000), and for each item perform some type of transactional activity. We're looking to perform two types of transactional flows:
1. When the cron executes, the entire thing is in a transaction, it all completes or it all rolls back. The transaction timeout needs to be configurable per cron.
2. The cron should not be transactional, -or- the nested invocations within the cron must be nested and committed transactions, so that if an individual iteration fails, the overall cron is not rolled back, and if the overall cron fails, the individual iterations that have been completed remain committed.
We're having numerous problems getting these scenario's to work. Here's a few items I have questions upon.
a. I'd wanted to go pojo, but it seems for item 1 you can only set a transaction timeout with an EJB annotation. It seems that for item 2 you can only perform nested transactions within EJB's. Can any of this be done with the pojo architecture or does it all require EJB's?
b. If I follow the EJB path, I attempt to use @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) on a few EJB methods. When doing so, I notice none of the 'save' operations take effect until the entire Event context completes and the entire transaction is committed. It does not seem like the REQUIRES_NEW method is operating within it's own transaction.
c. Regardless of whether the Asynchronous method is marked with @Transactional or not... it always operates in a transaction, even if I don't want it to.
A related question is... how can I tell when I'm operating in a transaction or not? I've tried Transaction.instance().isActive(), but this does not seem to accurately reflect when a transaction is in effect. For example, omitting the @Transactional annotation from the asynchronous method the isActive method returns false; yet the 'save' operations performed by the method are in fact persisted to the database, and they are not persisted if I force an exception. I've also tried session.getTransaction() (we use hibernate persistence), and it's isActive method returns false; while it too is clearly operating within a transaction. Aside from watching the database itself, what's the best way to know when a transaction is active or not, and if it's a nested or new transaction? Is there some logging that can be enabled?
Thanks in advance... lots to ponder here.