-
1. Re: afterTransactionSuccess not firing
jfaath Feb 18, 2009 9:11 AM (in response to jfaath)Can someone please tell me under what conditions the
afterTransactionSuccess
event is supposed to fire? The document says:org.jboss.seam.afterTransactionSuccess — called when a transaction succeeds in the Seam Application Framework
Yet when I run a simple action that takes the injected EntityManager and persists an entity, no event is fired. My transactions are configured like this:
<transaction:entity-transaction entity-manager="#{entityManager}"/>
Does the entity have to be a Seam component? I would think the transaction should be noticed through the Seam-managed EntityManager.
-
2. Re: afterTransactionSuccess not firing
stefanotravelli Feb 18, 2009 10:05 AM (in response to jfaath)It is fired
when a transaction succeds in the Seam Application Framework
.Actually, this means that it's fired when you call entityHome.persist() or entityHome.update().
If you persist your entity by yourself, inside a custom DAO object, calling entityManager.persist(), issuing an entityManager.flush() during a long running conversation o whatever, that event will not be fired.
Looking at the source code of org.jboss.seam.framework.Home may help. Find all usages of raiseAfterTransactionSuccessEvent() method with a smart IDE to get the logic behind this feature.
-
3. Re: afterTransactionSuccess not firing
valatharv Feb 18, 2009 4:00 PM (in response to jfaath)Yes, I have an entity and
experimentSavedOrUpdated
method is invoked on call to persist or update@Name(
externalApplicationInvoker
)
@Scope(ScopeType.STATELESS)public class ExternalApplicationInvoker
{
@Observer(org.jboss.seam.afterTransactionSuccess.Experiment
)
public void experimentSavedOrUpdated()
{
executeData(getType(), getHjid());
}@Observer(
generateDataset
)
@Transactional
public void generateDataSet() {
executeData(getType(), getHjid());
}
}b) I am invoking this on an event from ui, which calls the above
generateDataset
observer.
public String generateDataset(){
//Events.instance().raiseAsynchronousEvent(generateDataset
,AA
,2
);
Events.instance().raiseEvent(generateDataset
);// can also pass arguments
returngenerateDataset
;
} -
4. Re: afterTransactionSuccess not firing
jfaath Feb 18, 2009 8:43 PM (in response to jfaath)Thanks for the reply Stefan.
I guess I was confused as to what exactly the Seam Application Framework is.
I figured since the entityManager is being managed as a Seam component and transactions are opened and committed via this entityManager, then these transactions were considered to be under the Seam Application Framework.
I'll take a look at the source code per your recommendation.
-
5. Re: afterTransactionSuccess not firing
swd847 Feb 19, 2009 4:17 AM (in response to jfaath)you may be interested in the event
org.jboss.seam.afterTransactionCompletion
andorg.jboss.seam.beforeTransactionCompletion
.These should be raised on every transaction if you are using the application framework or not.
-
6. Re: afterTransactionSuccess not firing
jfaath Feb 19, 2009 9:32 PM (in response to jfaath)Yep, that sounds like the event I was envisioning (which, fyi, doesn't appear to be in the documentation).
However, it doesn't seem to work with my use case from the first post as I am receiving an
EntityManager is closed
error when trying to refresh the entity query.Looks like I'll have to investigate using the Home object.
Thanks.
-
7. Re: afterTransactionSuccess not firing
swd847 Feb 19, 2009 9:40 PM (in response to jfaath)are you trying to use beforeTransactionCompletion or afterTransactionCompletion?
afterTransactionCompletion is called after the transaction is ended and has committed or rolled back, so the entityManager will be closed. I am not sure about beforeTransactionCompletion, the transaction should still be active but the entityManager may be closed. I only found out about them when I was poking around in the transaction code, I did not realize that they were not documented.