5 Replies Latest reply on Oct 29, 2009 1:46 PM by Pete Muir

    Problem Injecting Non-Serializable field

    Diego Coronel Apprentice

      Hey,


      Im testing webBeans and i got some errors trying to inject EntityManager


      I have a authenticator Bean that needs to inject entity manager:




      @Named
      @SessionScoped
      public class Authenticator implements Serializable {
           private static final long serialVersionUID = 1L;
           
           @Current
           private Credentials credentials;
           
           @Database
           private EntityManager entityManager;



      and the class that produces this field:




      public class PersistenceProvider implements Serializable {
           private static final long serialVersionUID = 1L;
           
           @Produces  @PersistenceContext @Database --> i tried with @ConversationScoped too
           private EntityManager entityManager;





      16:56:12,128 INFO  [WebBeansBootstrap] Web Beans 1.0.0-SNAPSHOT
      16:56:12,561 ERROR [AbstractKernelController] Error installing to Start: name=vfsfile:/C:/trabalho_diego/jboss-5.1.0.GA/server/web/deploy/HelloWebBeans.ear/_WebBeansBootstrapBean state=Create
      javax.enterprise.inject.IllegalProductException: The bean Session scoped simple bean 'authenticator' com.fpf.login.Authenticator,  API types = [Object, Authenticator, Serializable], binding types = [@Any, @Current] declares a passivating scope but the producer returned a non-serializable bean for injection: Annotated Dependent unnamed producer field bean [com.fpf.provider.PersistenceProvider] for class type [javax.persistence.EntityManager] API types [class java.lang.Object, interface javax.persistence.EntityManager], binding types [@javax.enterprise.inject.Any(), @com.fpf.provider.Database()]
           at org.jboss.webbeans.Validator.validateInjectionPoint(Validator.java:182)
           at org.jboss.webbeans.Validator.validateBean(Validator.java:69)
           at org.jboss.webbeans.Validator.validateRIBean(Validator.java:89)



      but i cant because it says that EntityManager isnt serializable, so, i did something wrong ?


      ty, sry about english