Actually this is one of those things that a bean is not supposed to be able to do and is the purpose of the UserTransaction object. If you can use that instead I definitely would as it will be portable to all impls that pass the Java EE TCK.

That said, you could add support for injection of that type via a PropertiesEditor like this one:

  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.transaction.TransactionManager;
  import java.beans.PropertyEditorManager;

public class TransactionManagerEditor extends java.beans.PropertyEditorSupport {

      static {
PropertyEditorManager.registerEditor(TransactionManager.class, TransactionManagerEditor.class);
      }

public void setAsText(String text) throws IllegalArgumentException {
          try {
              InitialContext context = new InitialContext();
              Object o = context.lookup("openejb:TransactionManager");
              setValue(TransactionManager.class.cast(o));
          } catch (NamingException e) {
              throw new IllegalStateException(e);
          }
      }
  }

  (or here: http://gist.github.com/231273 )

You just need to make sure the TransactionManagerEditor loads fairly early or move the register code close to the class where the TransactionManager is needed.

This *should* do the trick. You might need to add a corresponding <env-entry>, not sure if we require that. If we do you can use the env-entries.properties file which will not conflict with JBoss at all. (see http://openejb.apache.org/3.0/custom-injection.html)

We could probably add built in support for this, but for now the above should work.

I've added a jira for "extended" types usable with @Resource (i.e. non- standard), just to make sure we don't loose the feedback:

  https://issues.apache.org/jira/browse/OPENEJB-1104

Feel free to add some more if you have any you need. Here's the standard list:

  https://issues.apache.org/jira/browse/OPENEJB-370

Not sure if that is comprehensive, but seems to be just missing UserTransaction.

-David


On Nov 10, 2009, at 12:14 PM, Jean-Louis MONTEIRO wrote:


Hi,

it should definitely work.
Did you provide a mappedName ?

Jean-Louis


Totsline, Greg wrote:

Hi -

We are injecting a javax.transaction.TransactionManager into an EJB. It
works fine under JBoss, but under OpenEJB 3.1.2  we get an
OpenEJBException:

No provider available for resource-ref 'null' of type
'javax.transaction.TransactionManager' for 'MyBean'. This is the same
problem reported in

http://old.nabble.com/TransactionManager-injection-td19492820.html

Was there a resolution to this problem or a suggested work around?

Many Thanks.

-greg






--
View this message in context: 
http://old.nabble.com/TransactionManager-resource---no-provider-error-tp26288929p26289083.html
Sent from the OpenEJB User mailing list archive at Nabble.com.



Reply via email to