0 Replies Latest reply on Oct 30, 2002 1:16 PM by sseaman

    Transaction control in JSP Tags

      I have a question in terms of best practice.

      I have a custom tag that allows JSP files to get to an interation of EJB Entity objects. Now, normally the JSP would have issues if it tried to use any relationships that exist with the entity bean because it would occur outside of the transaction. So I came up with two seperate ways to address this issue and I am wondering which is better.

      The first way is to control transaction myself and begin a transaction in the doStartTag and then end the doEndTag. This allows all the code in the body of the tag in the JSP to remain in one transaction.

      The issue with this way is that if they error out in the JSP (say a NullPointerException or something) then next time the JSP is called the transaction will still be active and cause and error. The next call to the JSP will work fine since JSP will kill the already active transaction that caused the error.

      The second way I found around this is a bit more code intensive. In the doStartTag I again being the transaction but I also commit it in the doStartTag. What I do is read in the results of my finder method to the EJB into "buffer" objects that are non-ejb copies of my entity bean. This way the JSP can read all the data from the object without any EJB calls.

      The disadvantage to this is a little more of a performance hit (very small), but more code. I have to create a "buffer" object for each EJB entity object.

      Which way do you think it better? Is there a better way?

      Any opinions would be nice.

      Thanks!