8 Replies Latest reply on May 12, 2008 12:50 PM by I need a real name

    enitiy manager

    I need a real name Newbie

      hi



      @Scope(ScopeType.SESSION)
      @Stateless   
      public class CompanyManager implements IFCompanyManager {
      
           public Company m_Company;
           public UserManager m_UserManager;
      
           @PersistenceContext
           EntityManager em;
           
           
           public CompanyManager(){
      
           }
      
           @In
           Company company;
           
      
           /**
            * 
            * @param CompanyDetails
            * @param SuperUserName
            * @param SuperUserEmail
            * @param Login
            */
           public Status RegisterCompany(IFCompany CompanyDetails, String SuperUserName, String SuperUserEmail, String Login){
                try {
                     System.out.println("inside reg button in manager");
                     
                                    
                
                     List existing = em.createQuery("select u.companyId from Company u").getResultList();
                
                } catch (Exception e) {
                     System.out.println("inside catch");
                     e.printStackTrace();
                }
                
                return Status.SUCCESS;
           }





      in the above code, i am getting a nullpointer exception, where i write the query. Plz tell me where i went worn. when i execute this query in the msql query browser, its returning a result.
      plz help me with this???

        • 1. Re: enitiy manager
          Geoffrey De Smet Newbie

          EntityManager em is probably null? The createQuery method shouldn't return null.
          So that means that the em doesn't get injected during deployment, which it should if it's an EJB3 jar deployment with a META-INF/ejb-jar.xml file.


          Btw, it's very unconventional that you use a capital to start your method and parameter names: it makes your code harder to read, but it shouldn't cause any errors.

          • 2. Re: enitiy manager
            I need a real name Newbie

            Thank you a lot for the tip.


            im entirely new to this.
            here is my ejb-jar.xml.
            plz go through this and tell me if i need to change anything, inorder to make the entitymanager ready.



            <?xml version="1.0" encoding="UTF-8"?>
            <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" 
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
                     version="3.0">
                     
               <interceptors>
                  <interceptor>
                     <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
                  </interceptor>
               </interceptors>
               
               <assembly-descriptor>
                  <interceptor-binding>
                     <ejb-name>*</ejb-name>
                     <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
                  </interceptor-binding>
               </assembly-descriptor>
               
            </ejb-jar>


            • 3. Re: enitiy manager
              Ananthan Rudran Newbie

              how is your EntityManager named in components.xml?

              • 4. Re: enitiy manager
                I need a real name Newbie

                here is my components.xml



                <?xml version="1.0" encoding="UTF-8"?>
                <components xmlns="http://jboss.com/products/seam/components"
                            xmlns:core="http://jboss.com/products/seam/core"
                            xmlns:drools="http://jboss.com/products/seam/drools"
                            xmlns:security="http://jboss.com/products/seam/security"
                            xmlns:mail="http://jboss.com/products/seam/mail"
                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xsi:schemaLocation=
                                "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd 
                                 http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-1.2.xsd
                                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.2.xsd
                                 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-1.2.xsd
                                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd">
                
                   <core:init debug="true" jndi-pattern="@jndiPattern@"/>
                     
                   <core:manager concurrent-request-timeout="500" 
                                 conversation-timeout="120000" 
                                 conversation-id-parameter="cid" 
                                 conversation-is-long-running-parameter="clr"/>
                    
                   <core:managed-persistence-context name="entityManager"
                                              auto-create="true"
                               persistence-unit-jndi-name="java:/AWBEntityManagerFactory"/>
                               
                   <core:ejb installed="@embeddedEjb@"/>
                   
                   <drools:rule-base name="securityRules">
                       <drools:rule-files>
                           <value>/security.drl</value>
                       </drools:rule-files>
                   </drools:rule-base>
                
                   <security:identity authenticate-method="#{authenticator.authenticate}"
                                           security-rules="#{securityRules}"/>
                   
                   <event type="org.jboss.seam.notLoggedIn">
                       <action expression="#{redirect.captureCurrentView}"/>
                   </event>
                   <event type="org.jboss.seam.postAuthenticate">
                       <action expression="#{redirect.returnToCapturedView}"/>
                   </event>
                   
                   <mail:mail-session host="localhost" port="2525" username="test" password="test" />
                        
                   <!-- For use with jBPM pageflow or process management -->
                   <!--  
                   <core:jbpm>
                      <core:process-definitions></core:process-definitions>
                      <core:pageflow-definitions></core:pageflow-definitions>
                   </core:jbpm>
                   -->
                      
                </components>
                




                Any idea why the EntityManager is null????
                plz help .......

                • 5. Re: enitiy manager
                  fanto black Newbie

                  Sounds strange?
                  are you sure you have place the bean in ejb package?

                  • 6. Re: enitiy manager
                    I need a real name Newbie

                    Yes the bean is in ejb package itself.....

                    • 7. Re: enitiy manager
                      fanto black Newbie

                      then have you place the datasouce file in deploy directory?

                      • 8. Re: enitiy manager
                        I need a real name Newbie

                        the datasource file given below is in the deploy folder



                        <?xml version="1.0" encoding="UTF-8"?>
                        <datasources>
                           
                           <local-tx-datasource>
                              <jndi-name>AWBDatasource</jndi-name>
                              <connection-url>jdbc:mysql://localhost:3306/awb001</connection-url>
                              <driver-class>com.mysql.jdbc.Driver</driver-class>
                              <user-name>root</user-name>
                              <password>root</password>
                        <!-- 
                              <exception-sorter-class-name>
                                 org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
                              </exception-sorter-class-name>
                              <metadata>
                                 <type-mapping>mySQL</type-mapping>
                              </metadata>
                        -->
                           </local-tx-datasource>
                            
                        </datasources>