[jboss-user] [JBoss Seam] - Ehcache and 'manual' seam invocation
adamw
do-not-reply at jboss.com
Tue Feb 5 12:30:32 EST 2008
Hello,
I have setup a 2nd level cache for hibernate (ehcache) for some of my entities. And it works fine, if I access the site using a browser.
However, I also need to access the Seam components from a daemon thread; however the thread and the "browser threads" seem to have separate caches - if I modify something from the browser (in the DB), the change is not visible in the daemon thread, because it uses old cache values. But the values displayed in the browser (which are also read from the cache) are correct.
Here's what I do in the daemon thread:
| boolean createContexts = !Contexts.isEventContextActive() && !Contexts.isApplicationContextActive();
| if (createContexts) {
| Lifecycle.beginCall();
| }
|
| try {
| UserTransaction tx = null;
| boolean txStarted = false;
| try {
| tx = (UserTransaction) Component.getInstance("org.jboss.seam.transaction.transaction");
| if (tx.getStatus() != Status.STATUS_ACTIVE) {
| txStarted = true;
| tx.begin();
| }
|
| ((EntityManager) Component.getInstance("entityManager")).joinTransaction();
| ((UpdateHandler) Component.getInstance("updateHandler")).update();
|
| if (txStarted) {
| tx.commit();
| }
| } catch (Exception e) {
| try {
| if (txStarted) {
| tx.rollback();
| }
| } catch (SystemException e1) {
| Logging.getLog(UpdateManager.class).error("Exception when rolling back the transaction", e1);
| }
|
| e.printStackTrace();
| }
| } finally {
| if (createContexts) {
| Lifecycle.endCall();
| }
| }
|
So basically I:
* setup Seam contexts: Lifecycle.beginCall()
* start a transcation, if necessary
* invoke a method of a component (UpdateHandler.update())
* commit the transaction
* Lifecycle.endCall()
Am I missing something?
--
Regards,
Adam Warski
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4126662#4126662
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4126662
More information about the jboss-user
mailing list