7 Replies Latest reply on Sep 14, 2010 2:40 PM by lvdberg

    Websphere Extended PersistenceContext

      Hi ,

      I have an application which uses Stateless and Stateful session beans. We are using these 2 on a single page to show some values. I am getting an error related to Extended PersistenceContext.

      javax.el.ELException: /po/purchaseOrderView.xhtml @82,72 value="#{purchaseOrderQueries.orderHdrInboxList}": javax.ejb.EJBException: 5.9.1 A persistence context is associated to the current JTA transaction and it is different than the extend-scoped persistence context bound to this SFSB.
      This is the same error which i am getting throughout the application whenever i am trying SFSB and SLSB on a single page to show content. I have used the method 2 to load the SEAM application on the Websphere environment.
      Any help here will be greatly appreciated. Please let me know what files would i need to post here to find out more about the issue. Can someone help me with common errors / solutions to resolve such kind of a problem?

      Thanks

      Raminder
        • 1. Re: Websphere Extended PersistenceContext
          ambrish_kumar

          Hi Raminder,


          We faced this problem also.


          Check that your SLSB is in Page scope or not?


          If possible , send your code for both SLSB and SFSB.


          Regards,


          Ambrish

          • 2. Re: Websphere Extended PersistenceContext

            The SFSB is a session scope component and the SLSB is page scope / conversation scope object.


            The session scope bean reads out the data from the DB and displays it on screen. The page that i am referring to contains only this SFSB. I am referring to this code as this is the simplest code which uses Extended PErsistence Context.


            @Stateful
            @Scope(SESSION)
            @Name("purchaseOrderQueries")
            public class PurchaseOrderQueriesImpl extends SpectrumUIBaseAction implements
                            PurchaseOrderQueries {
            
                    @PersistenceContext(type = PersistenceContextType.EXTENDED)
                    private EntityManager em;
            
                    private String sortField = "getId.getDocumentNumber";
                    private boolean sortAscending = true;
            
                    @In(value = "currentUser", required = true)
                    private AuthUsers currentUser;
            
                    @In(required = false)
                    @Out(required = false)
                    List<MstCurrency> mstCurrencylist;
            
                    @In(required = false)
                    // @Out(required = false).. should not use..
                    private OrderHdr orderHdrEntity;
            
                    List<OrderHdr> orderHdrList;
            
                    List<OrderHdr> orderHdrListForClose;
            
                    List<OrderHdr> orderHdrListForEdit;
            
                    List<OrderHdr> orderHdrListForApproval;
            
                    List<MstDocumentTypes> mstDocumentTypeslist;
            
                    int pageIndex = 1;
            
                    @RequestParameter
                    String docNo;
            
                    @RequestParameter
                    String siteCode;
            
                    @RequestParameter
                    String finYr;
            
                    @In(required = false)
                    @Out(required = false)
                    List<OrderHdr> orderHdrInboxList;
            
                    @In(required = false, create = true)
                    private CommonQueriesMasterForAuthorization commonQueriesMasterForAuthorization;
            
                    public List<OrderHdr> getOrderHdrList() {
                            messageLogger.info("MasterAction: getOrderHdrList()");
                            messageLogger.info("MasterAction: getOrderHdrList():orderHdrEntity--> "
                                            + orderHdrEntity);
            
                            // This is just for Purchase ORder hence document types has to be
                            // Purcahse order only
            
                            String docNo = "";
                            String documentTypes = getProperty("DocumentType.PO");
                            StringBuffer siteCodeString = getSiteListForTransaction("task.PO.create");
            
                            if (orderHdrEntity != null && orderHdrEntity.getId() != null
                                            && orderHdrEntity.getId().getDocumentNumber() != null
                                            && !orderHdrEntity.getId().getDocumentNumber().equals("")) {
            
                                    messageLogger.info("getOrderHdrList():DocumentNumber--> "
                                                    + orderHdrEntity.getId().getDocumentNumber());
            
                                    if (orderHdrEntity.getId().getDocumentNumber() != null
                                                    && orderHdrEntity.getId().getDocumentNumber()
                                                                    .equalsIgnoreCase("")) {
                                            docNo = orderHdrEntity.getId().getDocumentNumber() + "%";
                                    }
            
                                    orderHdrList = em
                                                    .createQuery(
                                                                    "from OrderHdr o where "
                                                                                    + "o.mstDocumentTypes.documentType= :documentType "
                                                                                    + " and o.id.documentNumber like :documentNumber and o.status= :status and o.mstSite.siteCode in "
                                                                                    + siteCodeString.toString()).setParameter(
                                                                    "documentType", documentTypes).setParameter(
                                                                    "documentNumber",
                                                                    orderHdrEntity.getId().getDocumentNumber() + "%")
                                                    .setParameter("status", true).getResultList();
                                    messageLogger.info("MasterAction: getOrderHdrList().size-->"
                                                    + orderHdrList.size());
                                    return orderHdrList;
                            } else if (orderHdrList == null) {
            
                                    orderHdrList = em
                                                    .createQuery(
                                                                    "from OrderHdr o where "
                                                                                    + "o.mstDocumentTypes.documentType= :documentType and o.status= :status and o.mstSite.siteCode in "
                                                                                    + siteCodeString.toString()).setParameter(
                                                                    "documentType", documentTypes).setParameter(
                                                                    "status", true).getResultList();
                                    messageLogger.info("MasterAction: getOrderHdrList().size-->"
                                                    + orderHdrList.size());
                                    return orderHdrList;
            
                            } else {
                                    return orderHdrList;
                            }
            
                    }
            
            }
            
            

            • 3. Re: Websphere Extended PersistenceContext
              The error that i get on the screen is given below


              javax.el.ELException: /po/purchaseOrderView.xhtml @82,72 value="#{purchaseOrderQueries.orderHdrInboxList}": javax.ejb.EJBException: 5.9.1 A persistence context is associated to the current JTA transaction and it is different than the extend-scoped persistence context bound to this SFSB.

              • 4. Re: Websphere Extended PersistenceContext

                OK.... Now i know the problem....


                My SFSB is expecting SEAM to inject another SLSB (Seam injects it correctly) and both of these components have their own PersistenceContext objects. I am executing a function on SLSB from the SFSB and i think this is where the error is occurring...


                I tried moving the code of the injected component in to the SFSB and it started working fine. Does this mean that i cannot use any component (SEAM) with its own PersistenceContext in another SEAM component without having this issue or is this only occurring because of a SLSB and SFSB being used together.


                I feel if this is the case then the only workaround i can think of is by passing the Entity Manager from the Main SLSB in to the injected component to ensure that the context does not change. Is this a fair understanding ?


                Thanks


                Raminder

                • 5. Re: Websphere Extended PersistenceContext
                  lvdberg

                  Hi,


                  Why are you using the extended persistencecontext ? You are only quering the database and not saving anything. Additionally you could consider the Seam managed persistence context, just replace the @PersistenceContext with @In (assuming the EntityManager is properly configured and named em.)


                  Leo 

                  • 6. Re: Websphere Extended PersistenceContext

                    Hi Leo,


                    hmm you have a valid point. The reason may be we were using extended persistence is because we were using Session scope objects... So we believed that the PersistenceContext needs to automatically be upgraded to Extended... I understand from your comment that this may not be a requirement at all since we are just querying the db and not saving the data back after a long conversation..... I will try that and check if it works fine.


                    But wouldnt the problem still exist as we are having 2 different entitymanager components being used in different beans?


                    Thanks


                    Raminder


                    • 7. Re: Websphere Extended PersistenceContext
                      lvdberg

                      Hi,


                      I never experienced these problems with a Seam managed persistenceContext, but I did have problems with the normal EJB one. I also have scenario's with mixed persistenceContext, but I advice you not to do that, because it has caused me a lot of problems.


                      I never really digged into the subkject, but it seems that Seam does an excellent job on using its persistenceContext very, very efficiently and without any transaction problems.


                      Leo