8 Replies Latest reply on Jul 6, 2005 8:32 AM by Jens Elkner

    How to replace @Inject with @PersistanceContext?

    Michiel Hillmann Newbie

      Hello everybody,

      I'am trying to follow the trailblazer trail on how to create EJB3. However when I want to deploy the code to JBOSS 4.0.3.RC1 I get a message on the console:

      --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
      ObjectName: jboss.j2ee:service=EJB3,name=org.jboss.ejb3demo.AuthorsBean
      State: FAILED
      Reason: java.lang.TypeNotPresentException: Type javax.ejb.Inject not present

      The problem seems to originate from the AuthosBean which is created in a flash demo (http://trailblazer.demo.jboss.com/IDETrail/ejb3/slsb/)

      On the website of JBoss (http://wiki.jboss.org/wiki/Wiki.jsp?page=MigrationFromPreview5ToEJB3.0Beta) I can find documentation stating that the annotation @Inject is obsolete and I should use @PersistanceContext. However the compiler refuses to recognise this annotation. The error states "type mismatch: cannot convert from PersistanceContext to Annotation.

      I'am using JBOSS 4.0.3.RC1 which I downloaded using the installer.
      I'am using Eclipse 3.1.0 (Build id: I20050401-1645) AND JBoss Eclipse IDE 1.5.0.M1

        • 1. Re: How to replace @Inject with @PersistanceContext?
          Michiel Hillmann Newbie

          After some editing in the java file I managed to get te compiler to compile the source without any problems. I just cleaned up the code bij removing import statements and only adding the ones really nessesary.

          However when I then deploy the application to the Jboss Server, I get the following error

          INFO [Ejb3Module] EJB3 deployment time took: 4203
          10:44:06,343 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,name=org.jboss.ejb3demo.AuthorsBean
          java.lang.TypeNotPresentException: Type javax.ejb.Inject not present

          • 2. Re: How to replace @Inject with @PersistanceContext?
            Alex Taylor Newbie

            Try removing the import of Inject from the top of your entity class.

            Cheers,
            Alex.

            • 3. Re: How to replace @Inject with @PersistanceContext?
              Michael Engel Newbie

              Jboss-IDE 1.5M1 has not been fixed to add EJB3-PERISISTENCE.JAR to the class path. This is where the @PersistenceContext is located. Add it to you class path and see what happens

              • 4. Re: How to replace @Inject with @PersistanceContext?
                Michiel Hillmann Newbie

                Thanks everybody for trying to help me out.

                Unfortunatly all the suggested solutions didn't do the trick. Adding the ejb3-persistance.jar to the classpath helped a lot in so far that I could replace @inject with @PersistenceContext in AuthorsBean. However when I deploy the newly created *.war and *.ejb3 files to Jboss 4.0.2 (with EJB 3.0 Beta) Server I still get:

                20:23:12,796 INFO [Ejb3Module] EJB3 deployment time took: 4500
                20:23:12,890 ERROR [StatelessManager] Starting failed jboss.j2ee:service=EJB3,name=org.jboss.ejb3demo.AuthorsBean
                java.lang.TypeNotPresentException: Type javax.ejb.Inject not present
                at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:98)

                I will try to figure it out, but some extra help will be appreciated.

                Michiel

                • 5. Re: How to replace @Inject with @PersistanceContext?
                  Jens Elkner Apprentice

                  Use eclipse and make a Ctrl+Shift+O on each src file ;-)

                  • 6. Re: How to replace @Inject with @PersistanceContext?
                    Bill Burke Master

                    Delete *all* of your class files and recompile.

                    • 7. Re: How to replace @Inject with @PersistanceContext?
                      Michiel Hillmann Newbie

                      Thanks everybody for helping me out. Deleting the class files did the trick.


                      Unfortunately I'm stuck with the next problem.

                      After the successful deployment of the application on Jboss 4.0.3 I get the following error after I press the articles button for the very first time:


                      javax.ejb.EJBException: null; CausedByException is:
                      detached entity passed to persist: org.jboss.ejb3demo.Author
                      org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:46)
                      org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:70)
                      org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
                      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                      org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:72)
                      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                      org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
                      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                      org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
                      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                      org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:93)
                      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                      org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:183)
                      org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
                      org.jboss.aspects.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:30)
                      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                      org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:79)
                      $Proxy73.addArticle(Unknown Source)
                      org.jboss.ejb3demo.web.AuthorServlet.createArticles(AuthorServlet.java:54)
                      org.jboss.ejb3demo.web.AuthorServlet.doPost(AuthorServlet.java:42)
                      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

                      • 8. Re: How to replace @Inject with @PersistanceContext?
                        Jens Elkner Apprentice

                         

                        "MHI" wrote:
                        detached entity passed to persist: org.jboss.ejb3demo.Author


                        So, perhaps you need a refresh/merge instead of a persist ...