EJB is already associated with an incomplete transaction
zenig.szimmerman.sunshineradiology.com Jun 18, 2010 6:35 PMI am receiving the following error message. I am using Seam 2.2.0, Glassfish v2 and Hibernate.
[#|2010-06-18T18:02:30.277-0400|INFO|sun-appserver2.1|javax.enterprise.system.container.ejb|_ThreadID=20;_ThreadName=httpSSLWorkerThread-8080-0;| javax.ejb.EJBException: nested exception is: java.lang.IllegalStateException: EJB is already associated with an incomplete transaction java.lang.IllegalStateException: EJB is already associated with an incomplete transaction at com.sun.ejb.containers.BaseContainer.useClientTx(BaseContainer.java:3501) at com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:3323) at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1253) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:195) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127) at $Proxy319.isAwareOfContainerTransactions(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54) at org.javassist.tmp.java.lang.Object_$$_javassist_seam_1.isAwareOfContainerTransactions(Object_$$_javassist_seam_1.java) at org.jboss.seam.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:116) at org.jboss.seam.persistence.ManagedPersistenceContext.joinTransaction(ManagedPersistenceContext.java:125) at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:111)
Here is the code.
@Stateful @Name("userList") @Scope(SESSION) @Restrict("#{identity.loggedIn}") @TransactionAttribute(REQUIRES_NEW) public class UserListAction implements UserList, Serializable { private static final long serialVersionUID = -6838835156002279984L; @PersistenceContext private EntityManager entityManager; @In private IdentityManager identityManager; @DataModel private List<UserAccount> userAccounts; @DataModelSelection private UserAccount userAccount; @In private FacesMessages facesMessages; @Logger private Log log; @Factory @Observer("userConfirmed") public void getUserAccounts() { log.info("Pulling new users from persistence."); userAccounts = entityManager.createQuery("SELECT u FROM UserAccount u") .getResultList(); } public UserAccount getUserAccount() { return userAccount; } public void disableUser() { log.info("Disabling user #0", userAccount.getUsername()); new RunAsOperation() { public void execute() { identityManager.disableUser(userAccount.getUsername()); // TODO: Shouldn't need to do this! //userAccount.setEnabled(false); //entityManager.merge(userAccount); } }.addRole("admin").run(); getUserAccounts(); facesMessages.add("User disabled for user #0", userAccount.getUsername()); } public void enableUser() { log.info("Enabling user #0", userAccount.getUsername()); new RunAsOperation() { public void execute() { identityManager.enableUser(userAccount.getUsername()); // TODO: Shouldn't need to do this! //userAccount.setEnabled(true); //entityManager.merge(userAccount); } }.addRole("admin").run(); getUserAccounts(); facesMessages.add("User enabled for user #0", userAccount.getUsername()); } public void deleteUser() { log.info("Deleting user #0", userAccount.getUsername()); // TODO: RunAs only for testing purposes! new RunAsOperation() { public void execute() { identityManager.deleteUser(userAccount.getUsername()); } }.addRole("admin").run(); getUserAccounts(); facesMessages.add("User deleted for user #0", userAccount.getUsername()); } @Remove public void destroy() { } }
I am able to get it working using the Entity Manager though I should be able to do this using the Identity Manager. What could I be doing wrong?
identityManager.disableUser(userAccount.getUsername()); // TODO: Shouldn't need to do this! //userAccount.setEnabled(false); //entityManager.merge(userAccount);
Any direction would be appreciated!