5 Replies Latest reply on Oct 20, 2009 5:06 PM by leandro godoy

    Error in @in EntityManager

    leandro godoy Apprentice

      have possessions when using the seam, I began a new project using seamProject on jbossDeveloperStudio have a they give that extende of they give generic, and in my controller use this they give with the annotation @ in of the seam see my code





      
      
      
      
      # public abstract class DaoGeneric<T, ID extends Serializable> implements   IDaoGeneric<T, ID> {  
      #       
      #     @In(create=true,value="entityManager")  
      #     private EntityManager entityManager ;  
      #       
      #     private Class<T> classe;  
      #   
      #   
      #     public void salvar(T objeto) {        
      #         try {             
      #             objeto =entityManager.merge(objeto);  
      #         } catch (StaleStateException e) {             
      #             e.printStackTrace();  
      #         }   
      #         catch(ConstraintViolationException e){    
      #             e.printStackTrace();  
      #         }  
      #         catch (HibernateException e) {  
      #           
      #             e.printStackTrace();  
      #         }  
      #     }  
      
      
      
      My DAO
      # @Name("daoCargo")  
      # public class DaoCargo extends DaoGeneric<Cargo, Long> implements IdaoCargo {  
      #   
      #     public DaoCargo(){  
      #         super();  
      #           
      #     } 
      
      
      my Controller
      
         1. package br.com.lgweb.controller.genericController;  
         2.   
         3. /* 
         4. * To change this template, choose Tools | Templates 
         5. * and open the template in the editor. 
         6. */  
         7.   
         8.   
         9. import br.com.lgweb.controller.interfaces.CargoBean;  
        10. import br.com.lgweb.dao.genericDao.IDaoGeneric;  
        11. import br.com.lgweb.geral.entity.Cargo;  
        12. import br.com.lgweb.interfaces.dao.IdaoCargo;  
        13. import br.com.lgweb.jpaDao.DaoCargo;  
        14.   
        15. import java.io.Serializable;  
        16. import java.util.List;  
        17. import javax.ejb.Remove;  
        18. import javax.ejb.Stateful;  
        19.   
        20. import javax.persistence.EntityManager;  
        21. import javax.persistence.PersistenceContext;  
        22. import org.jboss.seam.ScopeType;  
        23. import org.jboss.seam.annotations.Begin;  
        24. import org.jboss.seam.annotations.Destroy;  
        25. import org.jboss.seam.annotations.End;  
        26. import org.jboss.seam.annotations.Factory;  
        27. import org.jboss.seam.annotations.In;  
        28. import org.jboss.seam.annotations.Name;  
        29. import org.jboss.seam.annotations.Out;  
        30. import org.jboss.seam.annotations.Scope;  
        31. import org.jboss.seam.annotations.datamodel.DataModel;  
        32. import org.jboss.seam.annotations.datamodel.DataModelSelection;  
        33. import org.jboss.seam.faces.FacesMessages;  
        34.   
        35.   
        36. /** 
        37. * 
        38. * @author godoy 
        39. */  
        40.   
        41. @Name("controlCargo")  
        42. @Scope(ScopeType.SESSION)  
        43. public class ControlCargoBean implements CargoBean, Serializable {  
        44.   
        45.      
        46.     @In(create = true)  
        47.     private transient FacesMessages facesMessages;  
        48.      
        49.     @In  
        50.     private Cargo cargo;  
        51.      
        52.     @DataModel  
        53.     @Out(required = false)  
        54.     private List<Cargo> cargos;  
        55.      
        56.     @In(create=true,value="daoCargo")  
        57.     private DaoCargo daoCargo ;  
        58.       
        59.     @DataModelSelection  
        60.     @Out(required=false,scope=ScopeType.SESSION)  
        61.     private Cargo selectedCargo;  
        62.   
        63.     public String excluir() {  
        64.         daoCargo.excluir(cargo);  
        65.         return "sucessDelete";  
        66.     }  
        67.   
        68.     @Factory("cargos")  
        69.     public void listarTodos() {  
        70.         cargos = daoCargo.listarTodos();  
        71.          
        72.     }  
        73.   
        74.     
        75.     public String editar() {  
        76.         cargo = daoCargo.findObjeto(cargo.getId());  
        77.         if (cargo != null) {  
        78.             return "editCargo";  
        79.         } else {  
        80.             facesMessages.addFromResourceBundle("entityNotFound");  
        81.         }  
        82.         return null;  
        83.     }  
        84.   
        85.      
        86.     public String salvar() {  
        87.         daoCargo.salvar(cargo);  
        88.         return "cargoPersist";  
        89.     }  
        90.   
        91.     @Destroy  
        92.     @Remove  
        93.     public void destroy() {  
        94.     }  
        95.   
        96.     public Cargo getCargo() {  
        97.         return cargo;  
        98.     }  
        99.   
       100.     public void setCargo(Cargo cargo) {  
       101.         this.cargo = cargo;  
       102.     }  
       103. }  
      
      
      
      The Error
      
      # 22:05:00,640 ERROR [application] org.jboss.seam.RequiredException: @In attribute requires non-null value: daoCargo.entityManager  
      # javax.faces.el.EvaluationException: org.jboss.seam.RequiredException: @In attribute requires non-null value: daoCargo.entityManager  
      #     at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)  
      #     at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)  
      #     at javax.faces.component.UICommand.broadcast(UICommand.java:387)  
      #     at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)  
      #     at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)  
      #     at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)  
      #     at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)  
      #     at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)  
      #     at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)  
      #     at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)  
      #     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)  
      #     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)  
      #     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
      #     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)  
      #     at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)  
      #     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)  
      #     at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)  
      #     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)  
      #     at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)  
      #     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)  
      #     at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)  
      #     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)  
      #     at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)  
      #     at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)  
      #     at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)  
      #     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)  
      #     at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)  
      #     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)  
      #     at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)  
      #     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)  
      #     at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)  
      #     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)  
      #     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:173)  
      #     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)  
      #     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)  
      #     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)  
      #     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)  
      #     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)  
      #     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:241)  
      #     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:447)  
      #     at java.lang.Thread.run(Unknown Source)  
      # Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: daoCargo.entityManager  
      


      Excuse, I am using a language translator
      What cause this mistake type? any help and well arrival. Thank you.

        • 2. Re: Error in @in EntityManager
          Bernard Labno Master

          Show your components.xml.

          • 3. Re: Error in @in EntityManager
            leandro godoy Apprentice

            Thanks for reply , my components.xml contain



            
            
            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
                        xmlns:core="http://jboss.com/products/seam/core"
                        xmlns:persistence="http://jboss.com/products/seam/persistence"
                        xmlns:drools="http://jboss.com/products/seam/drools"
                        xmlns:bpm="http://jboss.com/products/seam/bpm"
                        xmlns:security="http://jboss.com/products/seam/security"
                        xmlns:mail="http://jboss.com/products/seam/mail"
                        xmlns:web="http://jboss.com/products/seam/web"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation=
                            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
                             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
                             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
                             http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd">
            
               <core:init debug="true" jndi-pattern="@jndiPattern@"/>
            
               <core:manager concurrent-request-timeout="500"
                             conversation-timeout="120000"
                             conversation-id-parameter="cid"
                             parent-conversation-id-parameter="pid"/>
            
               <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
               <web:hot-deploy-filter url-pattern="*.seam"/>
            
               <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                  persistence-unit-jndi-name="java:/SeamProjectEntityManagerFactory"/>
            
               <drools:rule-base name="securityRules">
                  <drools:rule-files>
                     <value>/security.drl</value>
                  </drools:rule-files>
               </drools:rule-base>
            
               <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
            
               <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
            
               <event type="org.jboss.seam.security.notLoggedIn">
                  <action execute="#{redirect.captureCurrentView}"/>
               </event>
               <event type="org.jboss.seam.security.loginSuccessful">
                  <action execute="#{redirect.returnToCapturedView}"/>
               </event>
            
               <mail:mail-session host="localhost" port="25"/>
            
               <!-- For use with jBPM pageflow or process management -->
               <!--
               <bpm:jbpm>
                  <bpm:process-definitions></bpm:process-definitions>
                  <bpm:pageflow-definitions></bpm:pageflow-definitions>
               </bpm:jbpm>
               -->
            
            </components>
            

            • 4. Re: Error in @in EntityManager
              Nicklas Karlsson Master

              Tried something like


                   <persistence:managed-persistence-context name="entityManager"
                        auto-create="true"
                        entity-manager-factory="#{SeamProjectEntityManagerFactory}" />
              
                   <persistence:entity-manager-factory name="SeamProjectEntityManagerFactory"
                        persistence-unit-name="SeamProject" />
              
              

              • 5. Re: Error in @in EntityManager
                leandro godoy Apprentice

                Thank you,it worked, thank you, however if I take my controller with the annotation @ Statefull and its
                interface with @ Local no longer works, I need to configure it to run the EJB's in my project?