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

    @PreDestroy not working..?

    Daniel Elley Newbie


      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 =
      public class TestMBean implements MessageListener{
       /** Logger. */
       private static final Log log_ = LogFactory.getLog(TestMBean.class
       public void onMessage(Message message) {
       //do something here...
       public void preDestroy(){
       log_.debug("preDestroy called!!!");
      }//end class
      Any ideas?



        • 2. Re: @PreDestroy not working..?
          Daniel Elley Newbie

          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
          at org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory.start(JBossMessageEndpointFactory.j
          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..?
            Helmuth Melcher Newbie

            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;
            public class RankingBean implements Ranking {
             protected EntityManager em;
             public void keke(){}
             public void thisOneWorksFine() {
             public void thisOneNeverGetsCalled() {


            package ...;
            import javax.ejb.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 Newbie

              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..?
                Helmuth Melcher Newbie

                Method annotated with @Remove isnt called either.