8 Replies Latest reply on Jun 6, 2009 11:54 PM by Pete Muir

    possible to inject entitymanager with @current

    Stijn Cremers Novice

      Is it possible in webbeans to inject the EntityManager with @current just as you can inject the EntityManager in Seam with @In?



      Greetings

        • 1. Re: possible to inject entitymanager with @current
          Gavin King Master

          According to the spec yes, but I'm not sure if that's available yet in the RI.

          • 2. Re: possible to inject entitymanager with @current
            Stijn Cremers Novice

            It doens't work yet...


            I get the following error:




            2009-06-04 19:56:14,630 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Start: name=vfszip:/C:/Projects/MyThings/programs/jboss-5.1.0.CR1/server/default/deploy/mythings-ear-1.0.0-SNAPSHOT.ear/_WebBeansBootstrapBean state=Create
            javax.inject.UnsatisfiedDependencyException: The injection point   Field @Current private entityManager on Annotated class Class @Named @Stateful ExtraWageTypeActionBean
              Constructor public ExtraWageTypeActionBean();
              Method void @PostConstruct public init();
              Method void public remove(@Entity @Named @Table @NamedQueries ExtraWageType);
              Method void @Remove public destroy();
              Method void public save(@Entity @Named @Table @NamedQueries ExtraWageType);
              Method List public getExtraWageTypeList();
              Method void public final wait();
              Method void public final wait(long, int);
              Method void public final native wait(long);
              Method int public native hashCode();
              Method Class public final native getClass();
              Method boolean public equals(Object);
              Method String public toString();
              Method void public final native notify();
              Method void public final native notifyAll();
             with binding types [@Current] in  unnamed enterprise bean [be.cremers.mythings.money.domain.action.ExtraWageTypeActionBean] API types [class java.lang.Object, interface be.cremers.mythings.money.domain.action.ExtraWageTypeAction], binding types [@javax.inject.New()] has unsatisfied dependencies with binding types 




            Let say it works... what will be the type of the persistenceContext? always extended or should it be defined somewhere?


            • 3. Re: possible to inject entitymanager with @current
              Arbi Sookazian Master

              In 299, I did not see any examples with attribute for @PersistenceContext other than unitName, but apparently that is referring to the JPA annotation as there is no @PersistenceContext here: http://docs.jboss.org/webbeans/apidocs/1.0.0.ALPHA2/


              So I'm assuming the examples in 299 are the default (tx-scoped) as per:


              http://java.sun.com/javaee/5/docs/api/javax/persistence/PersistenceContext.html


              So what is the advantage/disadvantage of using @Current rather than @PersistenceContext to inject the EntityManager?

              • 4. Re: possible to inject entitymanager with @current
                Gavin King Master

                Arbi Sookazian wrote on Jun 05, 2009 07:08:


                So what is the advantage/disadvantage of using @Current rather than @PersistenceContext to inject the EntityManager?


                The same advantage as with any 299 injection, of course! You identify the EntityManager you are interested in using a typesafe binding, instead of a string-based unitName.

                • 5. Re: possible to inject entitymanager with @current
                  Gavin King Master

                  Stijn Cremers wrote on Jun 04, 2009 20:08:


                  It doens't work yet...


                  Did you actually declare it first?


                  i.e. using:


                  @Produces @PersistenceContext(unitName="xxx")
                  EntityManager entityManager;



                  Like I said, this is probably not implemented. But even once it is implemented, you will need to declare a persistence context before you can inject it.

                  • 6. Re: possible to inject entitymanager with @current
                    Arbi Sookazian Master

                    sounds right!


                    break: Rob Zombie - brick house


                    they didn't have any bands @ JavaOne in 2003...  well, maybe at night at the sausage fest vendor parties!

                    • 7. Re: possible to inject entitymanager with @current
                      Stijn Cremers Novice

                      I've tried with this:



                      @Produces @PersistenceContext(unitName="xxx")
                      EntityManager entityManager;



                      But, now i get the following error:



                      2009-06-05 20:20:52,239 ERROR [STDERR] (http-127.0.0.1-8080-1) java.lang.RuntimeException: javax.inject.ExecutionException: Error getting field entityManager on class be.cremers.mythings.money.domain.action.ExtraWageTypeActionBean
                      2009-06-05 20:20:52,270 ERROR [STDERR] (http-127.0.0.1-8080-1)      at org.jboss.ejb3.EJBContainer.invokeCallback(EJBContainer.java:1123)
                      ...
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1)      ... 81 more
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1) Caused by: java.lang.IllegalArgumentException: Can not set javax.persistence.EntityManager field be.cremers.mythings.money.domain.action.ExtraWageTypeActionBean.entityManager to be.cremers.mythings.money.domain.action.ExtraWageTypeAction_$$_javassist_14
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1)      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1)      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1)      at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1)      at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1)      at java.lang.reflect.Field.get(Field.java:358)
                      2009-06-05 20:20:52,286 ERROR [STDERR] (http-127.0.0.1-8080-1)      at org.jboss.webbeans.util.Reflections.getAndWrap(Reflections.java:456)




                      Like you're saying it is probably not implemented so i'll stop trying...


                      • 8. Re: possible to inject entitymanager with @current
                        Pete Muir Master

                        Right, this syntax isn't implemented, the RI is still using the XML declarations for persistence contexts (and other Java EE resources)