0 Replies Latest reply on Jul 26, 2010 6:01 PM by nifs

    How invoke a method of a class(TestBHome) in another class(TestAHome)

    nifs

      Hi everybody


      This may look very straightforward, but i don't know the correct way to do it.


      Consider two classes TestAHome and TestBHome, in the next scenario:


      //All the imports well declared
      
      @name("testAHome")
      public class TestAHome extends EntityHome<TestA> {
      
          @In IdentityManager identityManager;
      
          public void setTestAId(Long id) {
              setId(id);
          }
      
          public Long getTestAId() {
              return (Long) getId();
          }
          
          public boolean deleteTestA(String TestAName) {
      
              if(identityManager.deleteUser(TestAName)) {
      
                  new TestBHome().deleteATestA(TestAName);  //Here is the problem, in new TestBHome()
                  return true;
              }
              else {return true};
          }
      
      }
      



      And


      //All the imports well declared
      
      @name("testBHome")
      public class TestBHome extends EntityHome<TestB> {
      
          @In EntityManager entityManager;
          
          public void setTestBId(Long id) {
              setId(id);
          }
      
          public Long getTestBId() {
              return (Long) getId();
          }
          
          public void deleteATestA(String Aname) {
            
              List<TestA> testAlist = entityManager.createNamedQuery("findTestAs")
                                                   .setParameter("name",Aname)
                                                   .getResultList();
        
              for(TestA i : testAlist) {
                  setTestBId(i.getId());
                  remove();
                  clearInstance();
              }
      
          }
      
      }
      


      The entity beans TestA and TestB don't have any relationship in the database, but TestB has information related with TestA(TestAName); so if i wanna delete a TestA, i have to delete all the information that TestB has in relation to TestA.


      When i execute this code i get:


      Caused by javax.el.ELException with message: "java.lang.NullPointerException" 
      ...
      Caused by java.lang.NullPointerException with message: "" 
      



      So the fact is that i don't know how to call a method located in a class(That inherits from EntityHome) to TestAHome(That inherits from EntityHome too).


      If i try this:


      @name("testAHome")
      public class TestAHome extends EntityHome<TestA> {
      
          ... ...
          @In TestBHome testBHome;    
          ... ...
      
          public boolean deleteTestA(String TestAName) {
      
              if(identityManager.deleteUser(TestAName)) {
      
                  testBHome.deleteATestA(TestAName);  //Here the problem continues, in testBHome
                  return true;
              }
              else {return true};
          }    
      
      }
      



      I get:


      org.jboss.seam.InstantiationException with message: "Could not instantiate Seam component: TestAHome" 
      ...
      Caused by org.jboss.seam.RequiredException with message: "@In attribute requires non-null value: testAHome.testBHome" 
      



      So i'm confused, i want to execute deleteATestA from deleteATestA to perform a improved delete function, but i don't know the correct way to do this


      !!!Thanks in advance!!!