Stateful bean destruction wants extended EM to join a transaction and fails
---------------------------------------------------------------------------
Key: JBSEAM-426
URL:
http://jira.jboss.com/jira/browse/JBSEAM-426
Project: JBoss Seam
Issue Type: Bug
Components: Core
Affects Versions: 1.1
Reporter: Christian Bauer
@Name("register")
@Scope(ScopeType.CONVERSATION)
@Stateful
public class RegisterBean implements Register {
@In
private User currentUser;
@In(create = true)
private EntityManager caveatEmptorEM;
@In(create=true)
private transient FacesMessages facesMessages;
private String verifyPassword;
public String getVerifyPassword() {
return verifyPassword;
}
public void setVerifyPassword(String verifyPassword) {
this.verifyPassword = verifyPassword;
}
@Begin(join = true, flushMode = FlushModeType.MANUAL)
public String enterAccount() {
System.out.println("################### FLUSHMODE" +
((HibernateEntityManager)caveatEmptorEM).getSession().getFlushMode());
if (
verifyPasswordMismatch(currentUser.getPassword())
||
usernameExists(currentUser.getUsername())
) {
return null; // Redisplay page
} else {
return "profile";
}
}
@IfInvalid(outcome = Outcome.REDISPLAY)
public String enterProfile() {
return "confirm";
}
@End
public String doRegister() {
System.out.println("################### FLUSHMODE" +
((HibernateEntityManager)caveatEmptorEM).getSession().getFlushMode()); // This
is also wrong, different issue
if ( usernameExists(currentUser.getUsername()) )
return "register";
caveatEmptorEM.persist(currentUser);
caveatEmptorEM.flush();
// Remove the "currentUser" from the session context. This is a detached
object
// after this method returns. We don't want it to leak into the next
conversation!
Contexts.getSessionContext().remove("currentUser");
facesMessages
.addFromResourceBundle("SuccessfulRegistration");
return "login";
}
@Remove @Destroy
public void destroy() {}
...
}
Exception during @Destroy:
00:03:34,505 DEBUG [org.jboss.seam.contexts.Contexts] destroying: conversation
00:03:34,505 DEBUG [org.jboss.seam.core.Events] Processing
event:org.jboss.seam.preDestroy.conversation
00:03:34,505 DEBUG [org.jboss.seam.contexts.Contexts] destroying: register
00:03:34,505 DEBUG [org.jboss.seam.core.Events] Processing
event:org.jboss.seam.preDestroy.register
00:03:34,506 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context
search: caveatEmptorEM
00:03:34,506 DEBUG [org.jboss.seam.contexts.Contexts] found in conversation context:
caveatEmptorEM
00:03:34,507 DEBUG [org.jboss.seam.util.Naming] JNDI InitialContext
properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory,
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
00:03:34,507 DEBUG [org.jboss.seam.core.Events] Processing
event:org.jboss.seam.preRemoveVariable.register
00:03:34,507 DEBUG [org.jboss.seam.core.Events] Processing
event:org.jboss.seam.postRemoveVariable.register
00:03:34,507 DEBUG [org.jboss.seam.interceptors.RemoveInterceptor] Stateful component was
removed: register
00:03:34,508 WARN [org.jboss.seam.contexts.Contexts] Could not destroy component:
register
javax.ejb.EJBException: java.lang.IllegalStateException: EntityManager is closed
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
...
Caused by: java.lang.IllegalStateException: EntityManager is closed
at org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:42)
at
org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:447)
at
org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:442)
at
org.jboss.seam.core.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:91)
at sun.reflect.GeneratedMethodAccessor328.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:17)
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:101)
at org.jboss.seam.Component.callComponentMethod(Component.java:1642)
at org.jboss.seam.Component.unwrap(Component.java:1663)
at org.jboss.seam.Component.getInstance(Component.java:1501)
at org.jboss.seam.Component.getInstance(Component.java:1461)
at org.jboss.seam.Component.getInstanceToInject(Component.java:1688)
at org.jboss.seam.Component.injectFields(Component.java:1218)
at org.jboss.seam.Component.inject(Component.java:988)
at
org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:48)
I can't make the doRegister() method @End @Remove @Destroy, it throws exceptions.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira