Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    EMFProviderCMT on WebSphere 7

    Hi,
    i am trying to integrate SmartGWT (Power 3.0) CMT in my application running on WebSphere 7.
    I have a business logic EJBModule (EJBm) and a SmartGWT web application (GwtWEB).

    On fetch, EMFProviderCMT tries to get the EntityManager 'persistenceEM' using a java:comp/env lookup.

    The error is the following:

    [03/07/12 17.36.21:774 CEST] 00000022 SystemOut O === 2012-07-03 17:36:21,774 [ : 3] DEBUG EMF - [builtinApplication.instrJPA_fetch] Initializing default EMF provider: com.isomorphic.jpa.EMFProviderCMT
    [03/07/12 17.36.21:778 CEST] 00000022 SystemOut O === 2012-07-03 17:36:21,777 [ : 3] WARN RequestContext - dsRequest.execute() failed:
    javax.persistence.PersistenceException: Unable to acquire entity manager.
    at com.isomorphic.jpa.EMFProviderCMT.getEntityManager(EMFProviderCMT.java:157)
    at com.isomorphic.jpa.EMF.getEntityManager(EMF.java:129)
    at com.isomorphic.jpa.JPADataSource.execute(JPADataSource.java:422)
    at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:721)
    at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
    at com.isomorphic.application.AppBase.execute(AppBase.java:491)
    at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1948)
    at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:199)
    at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:156)
    at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:121)
    .
    .
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
    Caused by: javax.naming.NameNotFoundException: Name "persistenceEM" not found in context "java:comp/env".
    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1178)
    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1095)
    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1233)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:395)
    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1276)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:364)
    at com.isomorphic.jpa.EMFProviderCMT.getEntityManager(EMFProviderCMT.java:155)
    ... 41 more


    I think the problem is the WebSphere JNDI context management. WebSphere doesn't map EntityManager objects in local JNDI context. I can manually map an EntityManager only in global JNDI context.
    Is this the cause?
    In this case, is there a way to force a lookup from global JNDI context?



    These are my main settings:


    My JPA settings in server.properties in GwtWEB:

    jpa.emfProvider: com.isomorphic.jpa.EMFProviderCMT

    jpa.entityManager: persistenceEM
    jpa.entityManagerFactory: persistenceEMF



    My test.ds.xml in GwtWEB:

    <DataSource
    ID="test"
    serverConstructor="com.isomorphic.jpa.JPADataSource"
    autoDeriveSchema="true"
    schemaBean="myEntityClass"
    >

    </DataSource>



    My ebj-jar.xml in EJBm:

    <session>
    <ejb-name>ProvaEAO</ejb-name>

    <home>it.ccg.ejbtest.server.eao.ProvaEAOHomeRemote</home>
    <remote>it.ccg.ejbtest.server.eao.ProvaEAORemote</remote>

    <local-home>it.ccg.ejbtest.server.eao.ProvaEAOHomeLocal</local-home>
    <local>it.ccg.ejbtest.server.eao.ProvaEAOLocal</local>

    <business-local>it.ccg.ejbtest.server.eao.ProvaEAOBusinessLocal</business-local>
    <business-remote>it.ccg.ejbtest.server.eao.ProvaEAOBusinessRemote</business-remote>

    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>

    <persistence-context-ref>
    <persistence-context-ref-name>persistenceEM</persistence-context-ref-name>
    <persistence-unit-name>EJBTestPersistence</persistence-unit-name>
    <persistence-context-type>Transaction</persistence-context-type>

    </persistence-context-ref>

    <persistence-unit-ref>
    <persistence-unit-ref-name>persistenceEMF</persistence-unit-ref-name>
    <persistence-unit-name>EJBTestPersistence</persistence-unit-name>

    </persistence-unit-ref>
    </session>



    My persistence.xml in EJBm:

    <persistence-unit name="EJBTestPersistence" transaction-type="JTA">
    .
    .
    </persistence-unit>



    Thanks in advance for your help.

    #2
    Hi,

    I haven't seen your code...
    Most probably you should use EMFProviderBMT (instead of EMFProviderCMT).

    EMFProviderCMT can be used only if you are executing data source logic from within EJB (extremely rare case).

    Regards,
    Alius

    Comment


      #3
      First, thank you alius for your help.

      I don't use EMFProviderBMT because i have my persistence logic in the EJB module (EJBm), not in the WEB module.


      Thanks,

      Giervella

      Comment


        #4
        Hi,

        Lets clarify:
        a) do you have JPA mapped beans bundled in EJB modules or
        b) do you have actual logic (fetching, updating, removing) coded in your EJBs.

        Snippet of your data-source config allows to deduce that it is a). Actual data manipulation is executed by JPADataSource code. It is OK to use EMFProviderBMT.

        In case of b) you should implement code which will execute your EJBs.

        If your case does not fit to specified above, you can create your own implementation of EMFProviderInterface.

        Regards,
        Alius

        Comment


          #5
          I have both:

          a) JPA mapped entity beans bundled in a EJB module;
          b) actual logic coded in EJBs (in the same EJB module).

          I implement some services in b) mode (as you say, i have code in WEB module which execute my EJBs in EJB module).
          I implement other services in a) mode.

          As you correctly deduced, my question is about the a) case. My EJB module contains JPA mapped entity beans. So, the related persistence.xml is in EJB module.
          As you saw in the snippet of my data-source, actual data manipulation is executed by JPADataSource code.
          "myEntityClass" value of schemaBean attribute is the complete class name of a JPA entity bean in EJB module.
          You say it is ok to use EMFProviderBMT, but it seems i cannot use it. It wants a persistence unit ref mapped in web.xml (this means it requires to find persistence.xml in WEB module, but my persistence.xml is in EJB module). I tried it days ago, but i had the "persistence unit not found in WEB module" error.


          I know there is the way to create my own implementation of EMFProviderInterface.
          If no built-in EMFProvider works out of the box for my application, i will create my implementation.


          I focus on EMFProviderCMT because it seems it matches with my application framework.
          It requires an EntityManager object and a EntityManagerFactory object mapped in ejb-jar.xml (so, in my EJB module).

          Comment


            #6
            Thanks,

            Giervella

            Comment


              #7
              I can not help you with specific answer as long as I do not know structure of your project.

              Anyway I would suggest you to find a correct config for standard JPADataSource implementetion with EMFProviderBMT (it is correct transaction usage for this case).

              Use additional configs for data sources with EJB invocation. Look in "Additional configurations" section in
              http://www.smartclient.com/docs/8.2/...jpaIntegration

              Regards,
              Alius

              Comment


                #8
                Thanks for your help Alius.

                Giervella

                Comment


                  #9
                  I am still waiting for a response by SmartGWT administrators..

                  Comment


                    #10
                    Hi,

                    You are aleady talking to the person who have written JPADataSource. That is me ;)

                    Regards,
                    Alius

                    Comment


                      #11
                      Ok!
                      As i saw, i have my persistence.xml in the EJB module.
                      As you know, i cannot use EMFProviderBMT because it expects to find the persistence.xml in the WEB module.

                      The framework of my application is the following:

                      - EJB module. Implements JPA facet and EJB facet.
                      - WEB module. It is the SmartGWT module.

                      So, EMFProviderBMT (which search the persistence.xml in WEB module, it wants the persistent unit mapped in web.xml) cannot work for me.

                      EMFProviderCMT is what matches with my application framework. It expects to find a EntityManager of a EJBean mapped in ejb-jar.xml.
                      So, it tries to lookup a EntityManager resource located in a ejb business logic module (my EJBmodule).

                      Now, since:
                      - as you know, EMFProviderCMT tries to lookup the EntityManager from local JNDI namespace (java:comp/env);
                      - WebSphere 7 doesn't map EntityManager resources neither in global JNDI namespace or in local JNDI namespace (java:comp/env);

                      my questions are:

                      1) can i use EMFProviderCMT out of the box?
                      2) i can manually map an EntityManager in global JNDI namespace.
                      If i do this, can i force EMFProviderCMT to look up the EntityManager from global JNDI namespace or i have to create my own EMFProviderInterface implementation to do this?



                      Thank you for your help Alius.

                      Giervella

                      Comment


                        #12
                        Both (EMFProviderBMT and EMFProviderCMT) looks up EntityManager and EntityManagerFactory in JNDI (java:comp/env) via configured names.

                        Difference between these implementations is transaction handling:

                        EMFProviderBMT looks up transaction in java:comp/UserTransaction;
                        EMFProviderCMT looks up transaction in java:comp/EJBContext;

                        EMFProviderBMT actually commits and rolls back transaction;
                        EMFProviderCMT does nothing on commit (allows container to commit); marks setRollbackOnly() on rollback.

                        So you have to correctly configure JNDI names for EntityManager and EntityManagerFactory as specified in docs http://www.smartclient.com/docs/8.2/...jpaIntegration

                        As I said earlier: for your case you must use EMFProviderBMT

                        Regards,
                        Alius

                        Comment


                          #13
                          To use EMFProviderBMT:
                          1) i configured JNDI names for EntityManager and EntityManagerFactory as specified in docs http://www.smartclient.com/docs/8.2/...jpaIntegration.
                          2) i mapped <persistence-context-ref> and <persistence-unit-ref> in web.xml of my WEB module.

                          Result:

                          JPAApplInfo E CWWJP0029E: Il server non riesce a trovare l'unità di persistenza MY_PERSISTENCE_UNIT nel modulo WEBmodule.war ed applicazione APP_EAR.

                          As i said, i have my persistence.xml in EJB module, not in WEB module.


                          What are the errors in my configuration for EMFProviderBMT?


                          Thanks Alius,

                          Giervella

                          Comment


                            #14
                            Looks like problem is not in configuration for EMFProviderBMT.
                            Problem that persistence.xml is not visible to server.

                            Can you tell me path to persistence.xml in you application, path to JPA mapped entities, path to web application server-side code?
                            Should look like this: app.ear/someFile.jar/someFolder/.../

                            You always emphasize that you have persistence.xml in EJB module. Does it mean that you deploy EJB and WEB modules separately?
                            If yes then you will not have access neither to persistence.xml nor to JPA mapped entities. In this case you should have a copy of jar (with persistence.xml and JPA entities) in your WEB module.
                            If EJB and WEB modules are in the SAME app then your persistence.xml is in wrong place.

                            Alius

                            Comment


                              #15
                              Sorry i posted the error message in my language.
                              The error is:
                              JPAApplInfo E CWWJP0029E: Server doesn't find persistence unit MY_PERSISTENCE_UNIT in WEBmodule.war and APP_EAR application.


                              Here my paths:

                              APP.EAR/EJBmodule.jar/ejbModuleRoot/META-INF/persistence.xml
                              APP.EAR/EJBmodule.jar/ejbModuleRoot/entity/an_antity.java
                              APP:EAR/WEBmodule.war/webModuleRoot/server/some_server_side_code.java


                              I have a EAR project (APP.EAR) which contains the EJB module and the WEB module. So, i deploy the EAR.
                              But this is the same to deploy the two modules separately, thus are two distinct modules, they have distinct resources context.

                              Yes, as i said the WEB module cannot access to persistence.xml (nor to JPA mapped entities) because it is in EJB module. This is the reason why i said EMFProviderBMT doesn't match with the framework of my application.

                              So, what i understand after your last message is that EMFProviderBMT requires a persistence.xml in WEB module, and there is not a way to use a persistence.xml contained in an external module. Is it right?



                              Thank you alius,

                              Giervella

                              Comment

                              Working...
                              X