0 Replies Latest reply on May 20, 2007 1:07 AM by alexandre.garino

    Stateful + PreDestroy + EntityManager = NullPointerException

    alexandre.garino

      Hi,

      I?m currently working on a stateful session bean (jboss 4.2.0.CR2) and I need some help.

      In the annotated pre destroy method I get an exception if one method of the Hibernate session is invoked.

      Caused by: java.lang.NullPointerException
       at org.jboss.ejb3.entity.ManagedEntityManagerFactory.getNonTxEntityManager(ManagedEntityManagerFactory.java:59)
       at org.jboss.ejb3.entity.ManagedEntityManagerFactory.getTransactionScopedEntityManager(ManagedEntityManagerFactory.java:164)
       at org.jboss.ejb3.entity.hibernate.TransactionScopedSessionInvocationHandler.getSession(TransactionScopedSessionInvocationHandler.java:71)
       at org.jboss.ejb3.entity.hibernate.TransactionScopedSessionInvocationHandler.getHibernateSession(TransactionScopedSessionInvocationHandler.java:62)
       at org.jboss.ejb3.entity.hibernate.TransactionScopedSessionInvocationHandler.invoke(TransactionScopedSessionInvocationHandler.java:96)
       at $Proxy112.load(Unknown Source)
      

      The code fragment:

      public class CombinationWriterBean implements CombinationWriter {
      
       @PersistenceContext( unitName = "MyPu" )
       private Session session;
      
       [ ? ]
      
       @PreDestroy
       public void destroy() {
       getLogger().info("Invoking destroy method...");
      
       if ( ! isCommitted() ) {
       this.session.load( this.revision, this.revision.getId() );
       this.session.delete( this.revision );
       }
       }
      }


      Is this a bug or this design is not compliant with EJB specs. Is there an existing workaround to this issue?

      Any help would be appreciated.

      Regards,
      Alexandre