3 Replies Latest reply on May 7, 2002 2:22 PM by davidjencks

    UserTransaction vs. DataSource

    redhonda

      I am still confused about the two. When to use which?

        • 1. Re: UserTransaction vs. DataSource
          davidjencks

          Use UserTransaction when you want to control transaction boundaries in your code rather than declaratively (IMO always a bad idea)

          Use a DataSource when you want to use BMP instead of CMP. I recommend not using the commit/rollback methods on connections from a datasouce, even if you are using BMT. Although possible with BMT IMO it doubles the number of bad ideas and sidestepping the useful container services.

          Since they are totally unrelated, I'm not sure I'm getting what you are confused about.

          • 2. Re: UserTransaction vs. DataSource
            redhonda

            My understanding is that entity beans must use the container/declarative transaction approach and that each bean method will automatically create a JTA transaction in the beginning of the method and the tranaction ends right before the method exits. Then, how come some of the examples in jboss.org still use DataSource and JDBC connections? I don't understand and can't find anything that clearly explain why.

            Also, the ejbStore() of entity beans get called on each call to their getXXX()'s even when I used a UserTransaction to scope all getXXX()'s in my client (which is a servlet.) I don't want it to call ejbStore()after each getXXX() call. Please help.

            • 3. Re: UserTransaction vs. DataSource
              davidjencks

              BMP != BMT

              I don't know why you are getting the behavior you are seeing, but I recommend putting a session bean in between your servlet and entities, even if only to let you use declarative tx support.