Transaction demarcation ignored in stateless EJB

Discussions

EJB programming & troubleshooting: Transaction demarcation ignored in stateless EJB

  1. Transaction demarcation ignored in stateless EJB (2 messages)

    Hi, I'm using EJB3 stateless session 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 session bean 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 @TransactionAttribute s ( 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: 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"; Amit Kasher

    Threaded Messages (2)

  2. Maybe table model ?[ Go to top ]

    I had a similar problem once. The problem there was that I used the wrong model for my MySQL tables (MyISAM which is the default). Excerpt from MySQL manual: MySQL supports two different kinds of tables: transaction-safe tables (InnoDB and BDB) and not transaction-safe tables (HEAP, ISAM, MERGE, and MyISAM). If you use ISAM with auto-comit every statement is commited.
  3. Re: Maybe table model ?[ Go to top ]

    I was about to update that this is what I've just found... This was the problem. I Added the following line in my.ini file inside MySQL installation, and it solved it. default-storage-engine=innodb Hibernate automatic schema generation started creating tables using InnoDB, and atomic transactions now work. Thanks! Amit Kasher