[jboss-user] [EJB/JBoss] - Doing persistence operations in worker threads
rituraj_tiwari
do-not-reply at jboss.com
Sun May 25 04:49:20 EDT 2008
Folks,
I am running into a problem where I have come to a dead end after following several leads.
I am launching an operation asynchronously in a separate thread which gathers some info and then starts persisting some entities. Problem is, I cannot seem to get anything written to the database.
My current approach is to get the EntityManagerFactory and UserTransaction in my worker thread by doing a JNDI lookup:
| InitialContext ctx = new InitialContext();
| EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup( "java:/MyProjectEntityManagerFactory" );
| UserTransaction ut = (UserTransaction)ctx.lookup( "java:comp/UserTransaction" );
|
| EntityManager em = em = emf.createEntityManager();
|
As soon as the last line above is executed, I see the following message in my JBoss log file:
| 2008-05-25 01:14:30,093 DEBUG [org.hibernate.impl.SessionImpl] opened session at
| timestamp: 4963136594300928
| 2008-05-25 01:14:30,093 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
| 2008-05-25 01:14:30,093 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] No JTA transaction found
|
All persistent operations seem to work, but nothing gets written to the DB. I see the following log messages in server.log:
| 2008-05-25 01:21:20,718 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] delaying identity-insert due to no transaction in progress
|
Is there anything I can do to start a JTA transaction?
My environment is JBoss 4.2.2 and Seam 2.x
Thanks.
-Raj
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4153204#4153204
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4153204
More information about the jboss-user
mailing list