2 Replies Latest reply on Oct 4, 2005 1:47 PM by Hamdy Farid

    Remove CMP bean fail if called within MDB

    Hamdy Farid Newbie

      I am trying to remove an instance of a CMP entity bean.

      The entity bean PK looks like

      /**
       * @ejb.pk-field
       * @ejb.persistence column-name="id" jdbc-type="INTEGER" sql-type="SERIAL"
       * @jboss.persistence auto-increment="true"
       * @ejb.interface-method view-type="both"
       * @ejb.transaction type="Supports"
       */
       public abstract Integer getId();
      
       /**
       * @ejb.interface-method view-type="both"
       */
       public abstract void setId(Integer id);
      
      


      The following tags are added to the entity to allow genrating the ids
      * @jboss.entity-command name="informix-serial" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCInformixCreateCommand"
       * @jboss.entity-command-attribute name="method" value="getSerial"
      



      every time I try to execute a "remove" on the remote/local home, I get

      ERROR [STDERR] javax.transaction.TransactionRolledbackException: Internal error getting primary key field member id; CausedByException is:
       null; nested exception is:
       javax.ejb.EJBException: Internal error getting primary key field member id; CausedByException is:
       null


      To be more specific on how the "remove" call is reached
      - a stateful session bean create the entity in the DB
      - within the same session bean method, a JMS message is sent to JmsXA queue for further processing (JmsXA is used to make sure the messages will be sent AFTER commiting the DB creation)
      - the MDB is called with the message
      - the MDB perform some checks on the entity (this involves instatiating the entity by doing find by primary key)
      - in some cases the MDB would decide to delete that entity (That's when the error happen)

      When I try to delete the object directly within the session bean... everything works fine ? it looks the problem has somethignto do with the session/MDB transaction


      Can anyone help please.

      Thanks
      Hamdy


        • 1. Re: Remove CMP bean fail if called within MDB
          Hamdy Farid Newbie

          After more reading, I reliazed that I am getting myself into "dist transaction" domain so I did the following:
          - Implemented SessionSynchronization in my stateful session bean.
          - Modified my business methods to cache the JMS messages in a member of the session bean.
          - in "afterCompletion()" I am submitting the JMS messages to the queue (changed it back to XConnFactory instead of JmsXA)
          - On the MDB side, I can read attributes from my entity beans but when I try to remove it , it thows ClassCastException on the PK class

          My PK class is basically an Integer generated by xdoclet

          Anybody help ... PLEASE.

          Thanks

          • 2. Re: Remove CMP bean fail if called within MDB
            Hamdy Farid Newbie

            Yet another LOW point in my career as software designer.
            I found what was the problem and it has nothing to do with transactions

            I was doing remoteHome.remove(remoteInterface) which is failing becuase it expects a PrimaryKey (that's explain the Cast error).

            I don't know which transaction model should I follow
            - use JmsXA and enlist the JMS in the transaction [ I noticed sometimes
            the following message

            18:56:47,578 WARN [TxConnectionManager] Prepare called on a local tx. Use of local
            transactions on a jta transaction with more than one branch may result in inconsistent
            data in some cases of failure.


            - use afterCompletion(true) to send my JMS

            Thanks for your help