UT factory lookup failed when trying to obtain a UserTransaction from a standalone client

March 20th, 2009

Applies to:
JBoss

Description:
Standalone client. You want to lookup a UserTransaction from JNDI according to the AS guide . You do it by specifying the properties for the InitialContext programmatically, like so:
UserTransaction tx = null;
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
“org.jnp.interfaces.NamingContextFactory”);
props.setProperty(Context.PROVIDER_URL, “jnp://localhost:1099″);
props.setProperty(Context.URL_PKG_PREFIXES, “org.jboss.naming:org.jnp.interfaces”);
InitialContext ctx = new InitialContext(props);
tx = (UserTransaction) ctx.lookup(“UserTransaction”);
tx.begin();

But the lookup does not work, instead you get a java.lang.RuntimeException: UT factory lookup failed

Cause:
The properties are not forwarded to the lookup within UserTransactionSessionFactory.

admin JAVA-JBoss

  1. admin
    March 20th, 2009 at 10:28 | #1

    For JBoss < 4.0.2, use a jndi.properties file instead of programmatic setup of the jndi properties. For JBoss >= 4.0.2, use the org.jboss.naming.NamingContextFactory instead of org.jnp.interfaces.NamingContextFactory. This factory provides the necessary functionality for the bugfix (remembering the last Properties passed to InitialContext()), see http://wiki.jboss.org/wiki/Wiki.jsp?page=NamingContextFactory.

  1. No trackbacks yet.