12 Replies Latest reply on Mar 29, 2013 5:43 AM by noelaa5

    [Jboss 7.1.3] ejbStore not called for EJB2 entity bean

    kkkppp

      Here is code snippet:

       

      final SWTable table = tableHome.findByPrimaryKey(tableID);
      final Long historyTableID = table.getHistoryTableID();
      if (historyTableID == null) return;
      final SWTable hstTable = tableHome.findByPrimaryKey(historyTableID);
      table.setHistoryTableID(null);
      hstTable.remove();

       

      it worked fine on Jboss 4.2, but fails on 7.1.3 - result of table.setHistoryTableID() is not written to DB and hstTable.remove() fails because violating foreign key.

      Is there any configuration parameter to get back old behaviour?

        • 1. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
          sergeg

          Looks like synchronization(on ejbFind/ejbRemove) works for CMP only:

           

          was:

           

          public class EntityContainer

          ...

             public void remove(Invocation mi)

                throws RemoteException, RemoveException

             {

                // synchronize entities with the datastore before the bean is removed

                // this will write queued updates so datastore will be consistent before removal

                Transaction tx = mi.getTransaction();

                if (!getBeanMetaData().getContainerConfiguration().getSyncOnCommitOnly())

                   synchronizeEntitiesWithinTransaction(tx);

          ...

             public Object find(Invocation mi) throws Exception

          ...

               // as per the spec 9.6.4, entities must be synchronized with the datastore when an ejbFind<METHOD> is called.
               if (!syncOnCommitOnly)
               {
                  synchronizeEntitiesWithinTransaction(tx);

           

           

          now:

           

          public class CmpEntityBeanHomeFinderInterceptorFactory extends EntityBeanHomeFinderInterceptorFactory {

          ...

          protected Object invokeFind(final InterceptorContext context, final EntityBeanComponentInstance instance) throws Exception {

          ...

                   // as per the spec 9.6.4, entities must be synchronized with the datastore when an ejbFind<METHOD> is called.

                  if (!store.getCmpConfig().isSyncOnCommitOnly()) {

                      cmpComponent.synchronizeEntitiesWithinTransaction(entityContext.getTransaction());

                  }

           

          and, afaiu, there are no synchronizeEntitiesWithinTransaction for BMP's ejbFind/ejbRemove  ?

          • 2. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
            kkkppp

            So it seems that behaviour is totally different for BMP beans in Jboss4 and AS7 in part of sync before ejbRemove invocation.

             

            Could anyone from Jboss team confirm/comment that? Also, what could I do without rewriting my EJB2 code? Is it possible to add my own container interceptor to somehow emulate old behaviour?

            • 3. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
              noelaa5

              Same problem here. I cannot use ejbRemove if entities are not synchronised.

               

              would there be any fix to this problem in future versions ?

               

              Thanks

              • 4. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                wdfink

                The behaviour of EJB2 entities is different in AS7 as the container is rewritten.

                From the ejb specification I'm not 100% sure whether ejbStore must be called during remove, from my understanding it is not necessary.

                 

                The configuration is not longer possible via conf/standardjboss.xml.

                In case of BMP you might patch the code which handle the entity inside the ejb3 module.

                • 5. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                  wdfink

                  With the next version of JBoss (AS8) there is no longer a support for EJB2 entities, the module and classes will be removed.

                  This is according to the JavaEE7 where the support of Entities and EB2 deployments is marked as 'pruned' and optional.

                   

                  So I would say there will be no fix for that in future releases.

                   

                  With EJB2 applications you might stay with AS5,

                  or the other possible option is to use the EAP version to request bugfixes, see Red Hat support policy.

                  • 6. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                    kkkppp

                    It's not about ejbStore called during ejbRemove, it's about synchronizing EJB transaction with database. Currently BMP entities are in sync only if ejbCreate was called within transaction, but not any other business method. So ejbRemove or ejbFind would work with DB in pre-transaction state which is not correct.

                    • 7. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                      noelaa5

                      Hi Wolf, Thanks for your reply.

                       

                      Given that JBoss7 supports EJB2.x , it s an obvious bug on BMP entities, i don t understand why wouldn t that be fixed ?

                      • 8. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                        wdfink

                        AS7 is the community part of JBoss, bugfixes might go into the next AS release which will be AS8. But unfortunately here EJB2 entities are not longer supported according to the spec (marked as optional).

                        You might try EAP6.1.Alpha which is equivalent to AS7.2.0, but I suppose the bug is not fixed here.

                         

                        If you are able to  contribute, use the github repository to provide a fix and send a pull-request.

                         

                        If you need to request a bugfix you have to switch to the supported EAP6 with a supscription to have bugfixes and security updates for a longer term, see Red Hat support policy.

                        • 9. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                          noelaa5

                          I tried to fix this issue myself but got some difficulties as it appears that the whole synchronising functionnality is not implemented for BMP entity beans.

                           

                          In class EntityBeanRemoveInterceptor, method processInvocation, I added the synchronising call

                           

                          entityBeanComponent.synchronizeEntitiesWithinTransaction.

                           

                          Problem is that method synchronizeEntitiesWithinTransaction. is defined only in child CmpEntityBeanComponent

                           

                          So having to define this method at the parent level EntityBeanComponent means moving all the synchronising code one level up which seems complicated.

                           

                          Is there any other ways to synchronise entities other than implementing all the logic at the EntityBean level ?

                           

                          Thanks,

                          • 10. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                            ohmygod

                            Hi kkkppp, how did you build jboss 7.1.3 version? Can you please suggest?

                            • 11. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                              kkkppp
                              • 12. Re: [Jboss 7.1.3] ejbStore not called for EJB2 entity bean
                                noelaa5

                                I suppose Mike s question is not a reply to my question:

                                 

                                Just to keep it alive:

                                 

                                I tried to fix this issue myself but got some difficulties as it appears that the whole synchronising functionnality is not implemented for BMP entity beans.

                                 

                                In class EntityBeanRemoveInterceptor, method processInvocation, I added the synchronising call

                                 

                                entityBeanComponent.synchronizeEntitiesWithinTransaction.

                                 

                                Problem is that method synchronizeEntitiesWithinTransaction. is defined only in child CmpEntityBeanComponent

                                 

                                So having to define this method at the parent level EntityBeanComponent means moving all the synchronising code one level up which seems complicated.

                                 

                                Is there any other ways to synchronise entities other than implementing all the logic at the EntityBean level ?

                                 

                                Thanks,