You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Thomas Veith <th...@web.de> on 2003/07/25 14:54:56 UTC

Problems with VelocityServlet/UserTransactions - Lifecycle (requestCleanup) related?

Hi,

I have a Webapp, deployed in JBoss-3.2.1, which basically consists of an AppServlet ( derived from org.apache.velocity.servlet.VelocityServlet ) that, depending of the Request, loads a Template in handleRequest(Request,Response,Context) which displays CMP2-Entity-Trees. Because you can have only access to CMR within the same transaction, I need a UserTransaction in the Servlet.

In createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  I fetch an InitialContext, resolve an UserTransaction, store it in request.getSession() and call tx.begin();

In requestCleanup(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Context context)  I get the Transaction back out of the HttpSession and call commit.

In error(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Exception cause)  I retrieve also the TransactionObject from the Session and do a rollback.

In my understanding this three methods are strongly related to each Request; therefore for any call on createContext() there is a call either to requestCleanup() or error().

Now, 1000 times it works as expected - but the next time the transaction will be created and not freed... resulting in a failure of retrieving a new transaction over the time cause of locking from an earlier generated ...

Do you have any ideas?

Best regards,

Thomas Veith



______________________________________________________________________________
ComputerBild 15-03 bestaetigt: Den besten Spam-Schutz gibt es bei 
WEB.DE FreeMail - Deutschlands beste E-Mail - http://s.web.de/?mc=021121


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problems with VelocityServlet/UserTransactions - Lifecycle (requestCleanup) related?

Posted by Nathan Bubna <na...@esha.com>.
Thomas Veith said:
...
> In createContext(...)  I fetch an InitialContext, resolve an
> UserTransaction, store it in request.getSession() and call tx.begin();
>
> In requestCleanup(...)  I get the Transaction back out of the
> HttpSession and call commit.
>
> In error(...)  I retrieve also the TransactionObject from the
> Session and do a rollback.
>
> In my understanding this three methods are strongly related
> to each Request; therefore for any call on createContext()
> there is a call either to requestCleanup() or error().

yeah, that sounds about right.

> Now, 1000 times it works as expected - but the next time the
> transaction will be created and not freed... resulting in a failure
> of retrieving a new transaction over the time cause of locking
> from an earlier generated ...
>
> Do you have any ideas?

i'm really not sure what the problem is, but have you tried storing your
UserTransaction as a HttpServletRequest attribute instead of putting it in the
HttpSession.  the whole idea of the session is that it persists across
multiple requests.  so, even if it doesn't fix your problem, storing request
lifecycle objects in the request attributes is the Right Way (tm).

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org