Hi,
I'm using EJB3 stateless beans and entities defined in the persistence API with
Hibernate validation annotations, all running in the same instance of JBoss 4.0.5 in the
same EAR file.
I have a stateless EJB with an injected EntityManager instance variable. Methods in this
bean use this entityManager to persist entity objects. I'm running a remote debugger
on JBoss and I stepping on the entityManager.persist(...) commands inside the stateless
bean implementation. At the same time I'm querying the DB (MySQL). I see that right
after each persist invocation, the table includes another row, meaning JBoss is committing
the transaction right after the persist, and not in the end of this method invocation.
I also tried throwing an exception from the bean between 2 persist commands, and I
actually see that the DB contains only one row (representing the first persist).
This is strange, since as far as I understand, the entire invocation should be atomic.
Have I misunderstood something...?
I tried marking the entire EJB with
@TransactionManagement(TransactionManagementType.CONTAINER) and marking the method with
several @TransactionAttributes (REQUIRED, REQUIRES_NEW).
A bit about the architecture of my application:
I have a servlet getting a reference from the JNDI to the stateless bean, which in turn
uses an injected entity manager to persist the just-created entities.
A bit about the structure of my application:
The servlet is in a WAR, the stateless bean is in another JAR, and the entities are in a
third archive (JAR).
The persistence.xml file is in the same JAR with the stateless bean, and it defines the
persistence unit in the following manner:
<persistence-unit name="mycontext">
which means that I'm injecting this persistence unit to the EJB in the following
manner:
@PersistenceContext(name = "mycontext") private EntityManager entityManager;
I'm getting the reference to that EJB from the servlet in the following manner:
(AuthenticationLocal)(new InitialContext().lookup(AuthenticationLocal.LocalJndiName)
(AuthenticationLocal.LocalJndiName is actually defined in AuthenticationLocal the
following way:
public static final String LocalJndiName = EAR_FILE_NAME + "/" +
AuthenticationBean.class.getSimpleName() + "/local";
Thanks,
Amit Kasher
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3991601#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...