2 Replies Latest reply on Mar 23, 2005 10:39 AM by tbech

    getiing Datasource/Connection in Session/Entity (beforeCompl

    tbech

      Hi all,
      I want to do some business checking in beforeCompletion. In order to do this I have to get the db connection.
      How to obtain the connection in easy portable way?
      Till now I've seen: use JNDI + hardcoded name of datasource, lookup, get datasource and getConnection.
      1. Is a connection retrieved in such a way, the same which is involved in transaction (which is required by me, is such behaviour in spec and/or the same in all application servers)? Or it is a new one unrelated connection/transaction ?
      2. How to get nicely the datasource name from the descriptor ? (I don't like hardcode the name in more places than one)

      Question about spec: why in EJBObject doesn't exists function getConnection? There would be no problems to access it with portable way.
      Thanks,
      Tom

        • 1. Re: getiing Datasource/Connection in Session/Entity (beforeC

           

          "tbech" wrote:

          Question about spec: why in EJBObject doesn't exists function getConnection? There would be no problems to access it with portable way.
          Thanks,
          Tom


          EJBObject is a proxy to the EJB. It certainly should not expose anything beyond
          the interface you define as the home or business interface.

          Exposing connections to clients is an anti-pattern, see the FAQ.

          • 2. Re: getiing Datasource/Connection in Session/Entity (beforeC
            tbech

            In fact I was thinking of EntityBean (instead of EJBObject) and only connection in the server layers, never to the client of course.
            There is often a need to have the connection (in server side layers) to do some queries (fast line reader design pattern) or huge-updates. And currently I don't see any good way of taking the connection - for me getting datasource by pointing/hardcoding datasource name is anti-pattern!