3 Replies Latest reply on Aug 21, 2002 11:17 AM by adrian.brock

    Transactions?  When to use them on session beans

    cyates

      Hi,

      I am using session facade with the session facade passing in VO objects to entity update() method.

      I assume I need a transaction on the entity bean's update() method, but do I need a transaction on the session (stateless) bean's method?

      Also, if I don't specify *any* transactions in ejb-jar or jboss*.xml what happens? Are they all surrounded by transactions?

      Thanks a lot guys.

      Colin Yates

        • 1. Re: Transactions?  When to use them on session beans

          One of the main points to the session facade
          is to wrap a group of entity operations in one
          transaction local to the server. The session facade
          starts the transaction.

          Use Required on all methods in the facade to achieve
          this.

          Technically the spec says you have to declare the
          transactions for a session bean. JBoss defaults to
          Required if you forget.
          For portability make it explicit.

          Regards,
          Adrian

          • 2. Re: Transactions?  When to use them on session beans
            cyates

            Thanks for your reply.

            What about if I have a method on a session (stateless) that executes some SQL on the server, then creates an entity bean.

            The situation I am talking about is for logging, we only want to record the last 300 activities so I create the activity using an entity bean then I execute some SQL.

            Do I have to wrap my SQL/JDBC call in it's own transaction or is this magically done for me?

            Thanks again

            • 3. Re: Transactions?  When to use them on session beans

              Assuming you are using a managed connection
              (from your configured DataSource in JNDI) to
              perform your SQL, JBoss will associate the connection
              with the transaction the session bean started.

              Regards,
              Adrian