  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | - Problem with Threads and Transactional context | - Problem with Threads and Transactional context 2007-07-16 - By zerok
Back Hi guys!
I've done the same post on Seam's, because I thought that would be a good place to put the question together with others posts with similar problem. As it is indeed an EJB3 related problem, I make the same post here too. So please don't be mad with me because this problem is taking away my sleep and may cost my job .
Here is the post: -- ---- ---- ---- --- I'm using threads inside a stateless bean and I cannot persist anything without having that annoying message that states I can only use transaction manager inside a transactional context. I've tried to make a busy-wait on my stateless bean so I can assure my bean will be alive until the very moment my thread needs the entityManager but when the execution reaches the entityManeger.merge( object ) an exception is risen. The story:
I have a jboss-4 (See http://oss-4.ora-code.com).0.5.GA with an upgrade on my original Javassist. Now I have javassist-3 (See http://ist-3.ora-code.com).4 due to issues with threads. My application needs to perform a fork in execution flow split in three parts. Both of them are created as threads and are observed in normal-fashion-way observer pattern, where the Stateless Bean is the observer. I have a hunch that my bean life-cycle ends before my first thread finishes, so the entityManager looses it transactional context. Can anybody point a blueprint for creating a structure to support such a business demand?
Here some parts of my code so you can place yourself. This code comes with only one thread. The original one has three, all like this one.
@(protected)(TransactionManagementType.CONTAINER) public @(protected)(name = "TempoRealRN") class TempoRealRNBean extends IntegratorCommonBehavior implements TempoRealRN, Observer {
@(protected)(beanName = "GenericoDAO") GenericoDAO genericoDAO;
@(protected) private EntityManager entityManager;
private static final Log log = LogFactory.getLog(TempoRealRNBean.class);
... public void processar(CommonController controladorComum) throws IntegratorException {
super.setEntityManager(this.entityManager);
tCorFrente = new ThreadCorFrente(controladorComum, this, log, dto, nomeThreadFrente, grupoFrente); tCorFrente.addObserver(this); tCorFrente.start(); }// ends of: public void processar(...) ....
/* * receives notification from thread state change and executes the proper action to acomplish bussiness rule goals. * */ public void update(Object o) {
//perform some state tests
//then try to persist. //at this point an exception is risen this.entityManager.merge( object );
}//ends public void update(Object o)
}//ends class
The exception risen is: -- ---- ---- ---- ---- --- 17:01:47,480 ERROR [STDERR] Caused by: javax.persistence .TransactionRequiredException: EntityManager must be access within a transaction 17:01:47,480 ERROR [STDERR] at org.jboss.ejb3.entity .ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:150) 17:01:47,480 ERROR [STDERR] at org.jboss.ejb3.entity .TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:180) 17:01:47,480 ERROR [STDERR] at wm.integrator.negocio.temporeal.impl .TempoRealRNBean.persistirFrente(TempoRealRNBean.java:485)
It would be great if some good soul could enlight me regarding on how to use the proper pattern for observing threads and how I can make this persistence work. Thank you all just for being patient enough to read this extensive post. I apologize myself for any English grammar misuse or misspell as English is not my 1st language. I'm from Brazil.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic &p=4064753#4064753
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode =reply&p=4064753 __ ____ ____ ____ ____ ____ ____ ____ ____ ____ jboss-user mailing list jboss-user@(protected) https://lists.jboss.org/mailman/listinfo/jboss-user
|
|
 |