0 Replies Latest reply on Mar 24, 2009 6:13 AM by aureliocalegari

    CMT weird behavior generates phantom entities.

    aureliocalegari

      Hello,

      I'm using JBoss 4.2.2 GA, EJB3, JPA with Hibernate 3.2.2GA provider and Oracle 10g.

      We have a massive operation where external clients (many external threads) access directly a Stateless Session Bean with the transaction demarcation REQUIRED, which means it'll start a transaction because the client was not in a transaction.

      The clients access a method such mySessionStub.dispatchJob(); By doing this, within this method I create a brand new Entity and call em.persist(myEntity); The entity is straight-forward. It has only 3 fields, including the ID that's being generated as sequence in the database. The EntityManager is injected in this session bean, which is a CMT session bean. So far so good!

      Imagine now my scenario of high intensive traffic. After a number of massive tests I noticed a weird behavior that at the very first glance I would think it's a hibernate issue. I created a dumb client thread pool which mimics 1000 clients accessing that session bean, but it does not allow more than 10 clients at time (I tried many configs from 1 to 50 concurrent clients to consume the 1000 queue), so the queue is consumed as each client invokes the mySessionStub.dispatchJob(); method. This method creates an entity in the database. After this I notice it's creating "phantom" entities, which means that in an intermittent behavior it's issuing more than one inserts per entity. So, after invoking the method 1000 times I ended up with 1035 or 1006 or 1018 entries in the database, but never 1000!

      I checked the hibernate generated inserts and I could see Hibernate was generating more inserts than expected, although the em.persist() method was being invoked no more than 1000 timers.

      I have switched the bean to BMT and I explicitly demarcated the transaction, then it worked perfectly. After all executions in many different configurations it generated only 1000 entities. Note, from the previous scenario (CMT), it only generates 1000 entities when I enforce ONE client thread at the moment! At the end my conclusions was that there might have an issue with the JBoss transaction propagation, not sure! Any thoughts?

      Thanks in advance

      Aurelio