0

I'm just testing to migrate from Seam3 to DeltaSpike, everything is ok if there is only one EntityManager in a bean, but there will be a error if add other EntityManager(other datasource):

JBAS010152: APPLICATION ERROR: transaction still active in request with status 0

the error project:

https://github.com/yuanqixun/hellodeltaspike

run this project environment:

  1. wildfly 8.2.0.Final
  2. H2 datasource
  3. MySql datasource

The EntityManagerProducer code:

@ApplicationScoped
public class EntityManagerProducer {

  @PersistenceUnit(unitName = "hellodeltaspike")
  EntityManagerFactory emf;

  @PersistenceUnit(unitName = "hellodeltaspike2")
  EntityManagerFactory mysqlemf;

  @Produces
  @ConversationScoped
  EntityManager createEntityManager(){
    return this.emf.createEntityManager();
  }

  @Produces
  @MySqlEm
  @ConversationScoped
  EntityManager createMysqlEntityManager(){
    return this.mysqlemf.createEntityManager();
  }

}

The Action code:

@ConversationScoped
@Named
public class PersonAction implements Serializable{

  @Inject
  EntityManager em;

  @Inject
  @MySqlEm
  EntityManager mysqlEm;

  Person person;

  List<Person> personList;

  @PostConstruct
  void afterCreate(){
    person = new Person();
    personList = queryPersonList();
  }

  private List<Person> queryPersonList() {
    String jql = "select o from Person o ";
    List<Person> result = em.createQuery(jql,Person.class).getResultList();
    if(result == null)
      return new ArrayList<Person>();
    return result;
  }


  @Transactional
  public void btnDoSave(ActionEvent event){
    try {
      if(StringUtils.isEmpty(person.getUuid())){
        em.persist(person);
      }else{
        em.merge(person);
      }
      em.flush();
      String msg = "Saved:"+person.getName();
      FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,msg,null));
      person = new Person();
      personList = queryPersonList();
    } catch (Exception e) {
      e.printStackTrace();
      FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), null));
    }
  }
...getter and setter
}

and there will be error: ERROR [org.jboss.as.txn] (default task-6) JBAS010152: APPLICATION ERROR: transaction still active in request with status 0

yuan
  • 1
  • 1
  • Welcome! You will probably get more support if you can narrow your problem to a minimum set to reproduce the error. Reading a whole project to debug it is a huge task, especially for people who are not paid. Good luck. – Cilyan Mar 28 '15 at 02:26
  • @Ciyan I have add sample code. – yuan Mar 28 '15 at 02:42

1 Answers1

-1

Modify the method's annotation,add the special qualifier of the right EntityManager, so the problem will be solved. But also has another problem, how to support multiple entityManager's transaction in one method?

@Transactional(qualifier = {H2Em.class})

yuan
  • 1
  • 1
  • #1 You are mixing managed and unmanaged code here. #2 If you are using an explicit qualifier here, you just restrict the EntityManager handling to the Entity-Managers with the specified qualifier/s. – Dar Whi Apr 12 '15 at 20:56