Announcement

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

    Handling transactions with EMFProviderLMT

    We are trying to implement a straigt forward DataSource backed by a JPA/Hibernate Entity.

    The DataSource looks like this:
    Code:
    <DataSource
        ID="CUSTOM_DATASOURCE"
        serverType="jpa"
        autoDeriveSchema="true"
        schemaBean="com.test.server.custom.entity.MyCustomEntity"
        >
       <fields>
          <field name="text" required="true"/>
          <field name="kurzbezeichnung"/>
          <field name="aktiv" type="boolean"/>
          <field name="sortierung"/>
       </fields>
    </DataSource>
    In server.properties we configured EMFProviderLMT as jpa.emfProvider and the data are shown in the clients grid.

    The problem now is however that after each IDA-Call there is a new connection to the database, because in our opinion the transaction does not get commited/rolled back before the EntityManager gets closed in the method EMFProviderLMT#returnEntityManager. In our understanding of the docs the framework should handle that automatically. We are using SmartGWTEE-Pro 6.0 and Hibernate 5.2.3.

    Are we missing something? Help would be appreciated!

    Thanks
    Last edited by krigu; 1 Nov 2016, 06:32.

    #2
    We recommend to enable DEBUG log level for com.isomorphic.jpa.JPADataSource category. Commits and rollbacks will be logged, and just in general more related details will be available.
    It may happen you will see the problem (if any) and be able to solve it yourself.
    Otherwise, please send us logs and more detailed description of what's wrong.
    Please let us know how it worked for you anyway, thanks.

    Comment


      #3
      We could reproduce the behaviour with any ds.xml-Datasource.. Here is another example:
      Code:
      <DataSource
          ID="NUTZUNG"
          serverType="jpa"
          autoDeriveSchema="true"
          schemaBean="com.mycompany.server.custom.entity.stammdaten.Nutzung"
          >
          <fields>
              <field name="text" required="true"/>
              <field name="kurzbezeichnung"/>
              <field name="aktiv" type="boolean"/>
              <field name="sortierung"/>
          </fields>
      </DataSource>
      The logs after a client-side fetch looks like this:
      Code:
      10:32:17,963 DEBUG [JPADataSource] [builtinApplication.NUTZUNG_fetch] Creating EntityManager and starting transaction.
      10:32:17,995 DEBUG [JPADataSource] [builtinApplication.NUTZUNG_fetch] Executing fetch.
      10:32:17,995 DEBUG [JPADataSource] [builtinApplication.NUTZUNG_fetch] Query string: select _Nutzung from Nutzung _Nutzung  order by _Nutzung.sortierung, _Nutzung.text
      Hibernate: 
          select
              count(nutzung0_.ID_NUTZUNG) as col_0_0_ 
          from
              TEST.NUTZUNG nutzung0_ 
          inner join
              TEST.STAMMDATEN nutzung0_1_ 
                  on nutzung0_.ID_NUTZUNG=nutzung0_1_.ID_STAMMDATEN
      Hibernate: 
          select
              * 
          from
              ( select
                  nutzung0_.ID_NUTZUNG as ID_STAMMDATEN1_171_,
                  nutzung0_1_.AKTIV as AKTIV2_171_,
                  nutzung0_1_.KURZBEZEICHNUNG as KURZBEZEICHNUNG3_171_,
                  nutzung0_1_.SORTIERUNG as SORTIERUNG4_171_,
                  nutzung0_1_.TEXT as TEXT5_171_ 
              from
                  TEST.NUTZUNG nutzung0_ 
              inner join
                  TEST.STAMMDATEN nutzung0_1_ 
                      on nutzung0_.ID_NUTZUNG=nutzung0_1_.ID_STAMMDATEN 
              order by
                  nutzung0_1_.SORTIERUNG,
                  nutzung0_1_.TEXT ) 
          where
              rownum <= ?
      10:32:18,002 DEBUG [JPADataSource] Releasing entity manager.
      With the built-in IntelliJ decompiler we can see that the EntityManager in EMFProviderLMT#returnEntityManager still has an open transaction. We fixed it temporarely with an (ugly) workaround and subclassed EMFProviderLMT and overrode the method returnEntityManager and commit the transaction there explicitly. Now it seems to work and the amount of connections doesn't increase with every request.

      Thanks for your help Isomorphic!

      Comment


        #4
        From the log you showed we assume that your DataSource is operating without RPCManager, is this correct? Then, instead of this temporary fix, you should commit/rollback the transaction on your own code using JPADataSource.onSuccess()/onFailure() APIs. Please take a look at our JPA Integration docs for more details and examples, scroll down to the "Transaction management".

        Comment


          #5
          I'll look into it.

          Thanks for your help! Much appreciated

          Comment

          Working...
          X