JBoss 4.0.3SP1
jdk 1.5.0_04
I'm a little confused about container manager transaction demarcation. I have a stateless session bean with a method that is invoked by the ejb timer service. It can potentially be a long running method but doesn't require any transaction capability (I don't need anything to roll back if the method doesn't succeed). So to avoid transaction timeout I marked the method as @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED). In this method however I do need to query the database and of course the entityManager must be accessed from within a transaction. So I moved my access of the entityManager into another method in the same ejb and marked it as @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW). I assumed that the container would start a new transaction each time the method which accessed the entityManager was called. However, when I run the application the i get the following error
Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction at org.jboss.ejb3.entity.ManagedEntityManagerFactory.getSession(ManagedEntityManagerFactory.java:124) at org.jboss.ejb3.entity.InjectedEntityManager.getSession(InjectedEntityManager.java:154) at org.jboss.ejb3.entity.InjectedEntityManager.createQuery(InjectedEntityManager.java:67)
So it looks like if I lookup another ejb of the same type and call the method that accesses the entityManager there will be a transaction associated with the call. If anyone knows a simpler way please let me know. Thanks.