5 Replies Latest reply on Oct 17, 2006 2:22 AM by plexiq

    @PreDestroy not working..?

    delley

      Hi,

      Im using a jboss 4.0.4GA with jboss-EJB-3.0_RC8-FD installed.

      I have a MDB that needs to do some cleaning before it is garbage collected.

      I have tried using @PreDestory or similar - but it doesnt seem like its ever being called!?!

      I have tried to deploy a new version of the code. Still nothing happend. I tried to shutdown jboss - nothing happend. Or at least no log statment in my logs. And it cant be my logging - have tested it and I know that it is working!

      I've read somewhere in this forum that @PreDestroy was moved from javax.ejb to javax.annotation. But as you can see from my import statment I'm using the correct one.

      And the library jboss-ejb3x.jar that contains the class is present in <jboss_home>\server\all\deploy\ejb3.deployer\ so it should be loaded - right?

      And yes - i'm starting jboss with the -c all switch ;-)

      import javax.annotation.PreDestroy;
      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.ObjectMessage;
      import javax.jms.JMSException;
      
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      
      @MessageDriven (activationConfig =
      {
       @ActivationConfigProperty(propertyName="destinationType",
       propertyValue="javax.jms.Queue"),
       @ActivationConfigProperty(propertyName="destination",
       propertyValue="queue/wipqueue")
      })
      public class TestMBean implements MessageListener{
      
       /** Logger. */
       private static final Log log_ = LogFactory.getLog(TestMBean.class
       .getName());
      
       public void onMessage(Message message) {
       //do something here...
       }
      
       @PreDestroy
       public void preDestroy(){
       log_.debug("preDestroy called!!!");
       }
      
      }//end class
      
      
      Any ideas?

      Regards,

      delley

        • 1. Re: @PreDestroy not working..?
          plexiq

          Im having a very similar problem with MD Pojo's:
          http://www.jboss.org/index.html?module=bb&op=viewtopic&t=92593

          • 2. Re: @PreDestroy not working..?
            delley

            tried to solve the issue by upgrading to jboss-EJB-3.0_RC9-FD.

            Now I cant even deploy my MDB...getting following exception (sigh):


            java.lang.RuntimeException: unable to determine messagingType interface for MDB
            at org.jboss.ejb3.mdb.MDB.getMessagingType(MDB.java:88)
            at org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory.resolveMessageListener(JBossMessage
            EndpointFactory.java:241)
            at org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory.start(JBossMessageEndpointFactory.j
            ava:184)
            at org.jboss.ejb3.mdb.MessagingContainer.startProxies(MessagingContainer.java:185)
            at org.jboss.ejb3.mdb.MessagingContainer.start(MessagingContainer.java:151)
            at org.jboss.ejb3.mdb.MDB.start(MDB.java:126)

            • 3. Re: @PreDestroy not working..?
              plexiq

              Mhm, spent some more hours on this problem.

              Im now using very very basic SLSB's, and i still cant get @PreDestroy working. Any hints?

              package ...;
              
              ..
              import javax.ejb.Stateless;
              import javax.persistence.EntityManager;
              import javax.persistence.PersistenceContext;
              ...
              import javax.annotation.PostConstruct;
              import javax.annotation.PreDestroy;
              
              @Stateless
              public class RankingBean implements Ranking {
              
               @PersistenceContext(unitName="...")
               protected EntityManager em;
              
               public void keke(){}
              
               @PostConstruct
               public void thisOneWorksFine() {
               System.err.println("PostConstruct.");
              
               }
              
               @PreDestroy
               public void thisOneNeverGetsCalled() {
               System.err.println("PreDestroy.");
               }
              }
              


              and

              package ...;
              
              import javax.ejb.Local;
              
              ...
              
              @Local
              public interface Ranking {
              
              public void keke();
              
              }
              


              I wasted lots(!) of time on this, and i'm really clueless what might be the reason for the problem. I'd appreciate any help a lot ;)

              • 4. Re: @PreDestroy not working..?
                abuayyub

                Add a method and annotate it with @Remove. See if the PreDestroy gets invoked before the ejb remove is called.

                • 5. Re: @PreDestroy not working..?
                  plexiq

                  Method annotated with @Remove isnt called either.