users@glassfish.java.net

Re: how to obtain a TransactionManager in a servlet?

From: <glassfish_at_javadesktop.org>
Date: Fri, 20 Apr 2007 13:41:42 PDT

Hi,

The correct way is
@Resource UserTransaction utx; and then you can use the UserTransaction APIs

You can read a brief explanation (if really interested can download blueprints solutions catalog for examples code) at
https://blueprints.dev.java.net/bpcatalog/ee5/persistence/webfacade.html

This example is a transaction around access to Java Persistence objects, but the APIs for UserTransaction are the same so might help to see.

UserTransaction is thread-safe so you can make it a field in a servlet and re-use it for multiple client requests also.

Anyways, the annotations and dependency injection is a useful feature to know about.

hth,
Sean
[Message sent by forum member 'sean_brydon' (sean_brydon)]

http://forums.java.net/jive/thread.jspa?messageID=213473