4 Replies Latest reply on Jan 18, 2012 12:59 AM by williamfitz

    Exception invoking: startup on an @In component

    bossy

      Hello,


      In my seam application I have an entity bean, corresponding to a table in my DB.




      @Entity
      @Table(name = "MY_TABLE")
      public class MyTable implements java.io.Serializable 
      {
           private String col1;
           private String col2;
      
           @In     ListHelper listHelper;
              .....
      }




      ListHelper is a component that I need in this entity bean. It looks like this:




      @Name("listHelper")
      @Scope(ScopeType.SESSION)
      @Startup
      public class ListHelper
      {
      }



      The problem I face is that when I deploy the application in JBOSS (4.2.3) I get the following exception
      during startup:




      13:42:52,766 ERROR [[/ABC]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: ABCEntityManagerFactory
           at org.jboss.seam.Component.newInstance(Component.java:2106)
           at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
           at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
           at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:112)
           at org.jboss.seam.init.Initialization.init(Initialization.java:735)
      
      .......
      Caused by: java.lang.RuntimeException: exception invoking: startup
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2219)
           at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
           at org.jboss.seam.Component.newInstance(Component.java:2094)
           ... 140 more
      Caused by: java.lang.reflect.InvocationTargetException
           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.util.Reflections.invokeAndWrap(Reflections.java:144)
           ... 143 more
      Caused by: java.lang.NoClassDefFoundError: Lcom/app/ListHelper;
           at java.lang.Class.getDeclaredFields0(Native Method)
           at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
           at java.lang.Class.getDeclaredFields(Class.java:1743)
           at org.hibernate.reflection.java.JavaXClass.getDeclaredFieldProperties(JavaXClass.java:76)
           at org.hibernate.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:100)
           at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:219)
           at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:134)
           at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:318)
           at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
           at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
           at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
           at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
           at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)
           at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)
           at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
           at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
           at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:85)
           at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
           ... 149 more
      Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: com.app.ListHelper
           at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:306)
           at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)
           at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
           at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
           ... 167 more
      13:42:52,766 ERROR [StandardContext] Error listenerStart
      13:42:52,766 ERROR [StandardContext] Context [/ABC] startup failed due to previous errors




      I'm not quite sure why I get this. I thought it might have something to do with the scope, but even changing  the scope of ListHelper to APPLICATION didn't help. So it's something else.


      Could someone help me with this? Is it actually possible to do this?


      Thanks

        • 1. Re: Exception invoking: startup on an @In component
          niox.nikospara.yahoo.com

          Hello,


          JBoss cannot find the class of the listHelper component. Where is this class? Where is the MyTable class? (My guess is that ListHelper is in the war while MyTable is in the ear.)


          Additionally you are injecting a Seam component into a non-seam class (MyTable doesn't have @Name, so it is not a Seam component...unless you have defined it in components.xml). This error will manifest after you solve the classpath problem.


          Last, it is most probably a logic/design error to have your model (the MyTable entity) depend on a service (the ListHelper component).

          • 2. Re: Exception invoking: startup on an @In component
            asookazian

            It is highly suspect and unusual (and most likely not recommended) to inject anything into a JPA entity class...


            What does ListHelper do and why does the entity class need access to its API?  It's possible to have business methods (active record style) in your entity class like in the Booking entity from the Seam booking example:


            @Transient
               public BigDecimal getTotal()
               {
                  return hotel.getPrice().multiply( new BigDecimal( getNights() ) );
               }



            But there is no injection in that class.  Typically JPA entity classes are JavaBeans with Hibernate Validator annotations.  Very simple.  They may possibly implement an interface (like public class Car implements IVehicle) to implement polymorphic queries, or extend a class, but that's about it.


            What you could do is add a setter method in that entity class (setListHelper(ListHelper listHelper)) instead.

            • 3. Re: Exception invoking: startup on an @In component
              bossy

              I see.


              Thank you guys, I understand now.


              I was trying to avoid setting  Many-2-One relationship for some of my lookup tables, but apparently I can't do it this way.

              • 4. Re: Exception invoking: startup on an @In component
                williamfitz

                You made several good points there. I did a search on the subject and found nearly all folks will consent with your blog.
                Classification Essay Help