0 Replies Latest reply on Jun 22, 2008 8:53 AM by Kevin Corby

    Strange problem deploying stateless component to Jboss

    Kevin Corby Newbie

      I have a stateless session bean that I can't deploy to Jboss as a seam component. It worked not long ago, and I'm not sure what I changed to break it. Everything seems straightforward and I'm at a loss, any suggestions are much appreciated. Jboss is 4.2.2.GA and Seam is 2.0.2.SP1. Here is the error I'm getting:


      02:34:24,597 INFO  [Initialization] Installing components...
      02:34:24,618 INFO  [Component] Component: UserDAOBean, scope: EVENT, type: JAVA_BEAN, class: com.ccri.gotm.auth.dao.UserDAOBean
      02:34:24,621 ERROR [[/gotm-gwt]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      java.lang.RuntimeException: Could not create Component: UserDAOBean
              at org.jboss.seam.init.Initialization.addComponent(Initialization.java:989)
              at org.jboss.seam.init.Initialization.installComponents(Initialization.java:911)
              at org.jboss.seam.init.Initialization.init(Initialization.java:589)
              at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
              at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
              at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
              at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
              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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
              at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
              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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
              at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
              at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
              at org.jboss.web.WebModule.startModule(WebModule.java:83)
              at org.jboss.web.WebModule.startService(WebModule.java:61)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
              at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
              at $Proxy0.start(Unknown Source)
              at org.jboss.system.ServiceController.start(ServiceController.java:417)
              at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy44.start(Unknown Source)
              at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
              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.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
              at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
              at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
              at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
              at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
              at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy45.start(Unknown Source)
              at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
              at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
              at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.jmx.adaptor.control.Server.invokeOpByName(Server.java:258)
              at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.invokeOpByName(HtmlAdaptorServlet.java:287)
              at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.processRequest(HtmlAdaptorServlet.java:102)
              at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.doGet(HtmlAdaptorServlet.java:77)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.IllegalArgumentException: @PersistenceContext may only be used on session bean or message driven bean components: UserDAOBean
              at org.jboss.seam.Component.checkPersistenceContextForComponentType(Component.java:874)
              at org.jboss.seam.Component.scanField(Component.java:850)
              at org.jboss.seam.Component.initMembers(Component.java:537)
              at org.jboss.seam.Component.<init>(Component.java:254)
              at org.jboss.seam.Component.<init>(Component.java:217)
              at org.jboss.seam.init.Initialization.addComponent(Initialization.java:974)
              ... 110 more
      



      Earlier in the log I see this which is encouraging:


      02:34:09,353 INFO  [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
      02:34:09,354 INFO  [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=gotm-ear-1.0-SNAPSHOT.ear,jar=gotm-ejb-1.0-SNAPSHOT.jar,name=UserDAOBean,service=EJB3 with dependencies:
      02:34:09,354 INFO  [JmxKernelAbstraction]      persistence.units:ear=gotm-ear-1.0-SNAPSHOT.ear,jar=gotm-ejb-1.0-SNAPSHOT.jar,unitName=gotm-ejb
      02:34:09,405 INFO  [EJBContainer] STARTED EJB: com.ccri.gotm.auth.dao.UserDAOBean ejbName: UserDAOBean
      



      Here is the code which is pretty basic:


      package com.ccri.gotm.auth.dao;
      
      import com.ccri.gotm.auth.entity.User;
      import com.ccri.gotm.dao.GenericDAO;
      import javax.ejb.Local;
      
      @Local
      public interface UserDAOLocal extends GenericDAO<User,Long> {
          public User findByName(String name);
      }
      




      package com.ccri.gotm.auth.dao;
      
      import com.ccri.gotm.auth.entity.User;
      import com.ccri.gotm.dao.GenericDAOImpl;
      import javax.ejb.Stateless;
      import org.jboss.seam.annotations.Name;
      
      @Stateless
      @Name("UserDAOBean")
      public class UserDAOBean extends GenericDAOImpl<User,Long> implements UserDAOLocal {
          public UserDAOBean() {
              super(User.class);
          }
      
          @Override
          public User findByName(String name) {
              return getSingleResultFromNamedQuery("findUserByName", 
                      User.class,
                      name);
          }
      }
      



      package com.ccri.gotm.auth.entity;
      
      import com.google.gwt.user.client.rpc.IsSerializable;
      import java.util.Set;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.ManyToMany;
      import javax.persistence.NamedQueries;
      import javax.persistence.NamedQuery;
      import javax.persistence.Table;
      import javax.persistence.UniqueConstraint;
      
      @Entity
      @NamedQueries({
          @NamedQuery(
              name="findUserByName",
              query="select u from User u where name = ?1"
          )
      })
      @Table(name="userentity", 
          uniqueConstraints={
          @UniqueConstraint(columnNames={"name"})
      })
      public class User implements IsSerializable {
          @Id
          @GeneratedValue(strategy=GenerationType.SEQUENCE)
          private Long id;
          
          private String name = "";
          private String password = "";
      
          @ManyToMany(fetch=FetchType.EAGER)
          private Set<Role> roles;
      
          public User() {
          }
      
          public Long getId() {
              return id;
          }
      
          public void setId(Long id) {
              this.id = id;
          }
          
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          public String getPassword() {
              return password;
          }
      
          public void setPassword(String password) {
              this.password = password;
          }
      
          public Set<Role> getRoles() {
              return roles;
          }
      
          public void setRoles(Set<Role> roles) {
              this.roles = roles;
          }
          
      }
      




      package com.ccri.gotm.dao;
      
      public abstract class GenericDAOImpl<T, IDCLASS>
              extends GenericReadOnlyDAOImpl<T, IDCLASS>
              implements GenericDAO<T, IDCLASS> {
      
          public GenericDAOImpl(Class<T> entityClass) {
              super(entityClass);
          }
      
          @Override
          public void save(T entity) {
              getEm().persist(entity);
          }
      
          @Override
          public T merge(T entity) {
              return getEm().merge(entity);
          }
      
          @Override
          public void remove(T entity) {
              getEm().remove(entity);
          }
      
          @Override
          public void refresh(T entity) {
              getEm().refresh(entity);
          }
      
          public void flush() {
              getEm().flush();
          }
      }




      package com.ccri.gotm.dao;
      
      public interface GenericDAO<T, IDCLASS> extends GenericReadOnlyDAO<T, IDCLASS> {
          public T merge(T entity);
          public void refresh(T entity);
          public void remove(T entity);
          public void save(T entity);
      }
      




      package com.ccri.gotm.dao;
      
      import java.util.List;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.NoResultException;
      import javax.persistence.PersistenceContext;
      import javax.persistence.PersistenceUnit;
      import javax.persistence.Query;
      
      public class GenericReadOnlyDAOImpl<T, IDCLASS> implements GenericReadOnlyDAO<T, IDCLASS> {
          @PersistenceUnit(unitName = "gotm-ejb")
          private EntityManagerFactory emf;
          
          @PersistenceContext(unitName = "gotm-ejb")
          private EntityManager em;
      
          private Class<T> entityClass;
      
          public GenericReadOnlyDAOImpl(Class<T> entityClass) {
              this.entityClass = entityClass;
          }
      
          public EntityManagerFactory getEmf() {
              return emf;
          }
      
          public void setEmf(EntityManagerFactory emf) {
              this.emf = emf;
          }
      
          public T get(IDCLASS primaryKey) {
              return em.find(entityClass, primaryKey);
          }
      
          public EntityManager getEm() {
              return em;
          }
      
          public Class<T> getEntityClass() {
              return entityClass;
          }
      
          public List<T> list() {
              return em.createQuery("from " + entityClass.getCanonicalName()).getResultList();
          }
      
          public void setEm(EntityManager em) {
              this.em = em;
          }
      
          public void setEntityClass(Class<T> entityClass) {
              this.entityClass = entityClass;
          }
      
          protected <R> R getSingleResultFromNamedQuery(String queryName,
                  Class<R> clazz, Object... params) {
              R rv = null;
              try {
                  Query q = getEm().createNamedQuery(queryName);
                  int position = 1;
                  for (Object param:params) {
                      q.setParameter(position++, param);
                  }
                  rv = (R) q.getSingleResult();
              } catch (NoResultException e) {
                  rv = null;
              }
              return rv;
          }
      
      }