users@glassfish.java.net

JNDI userTransaction not found

From: <glassfish_at_javadesktop.org>
Date: Fri, 04 May 2007 06:56:52 PDT

Hi All,
  I have difficulty to use distributed transaction from glassfish from my client app. I saw glassfish JIRA that ver 1 doesn't support it and the JIRA is closed for v2, so I download v2 beta.
  Now instead of getting an error when I call userTx.start() in ver1 I have nameNotFoundException while doing a JNDI lookup for java:comp/UserTransaction. The same code works for weblogic with weblogic context factory and provider url. The code is as below:

    public InitialContext getInitialContext(){
        return getInitialContext(null);
    }

    public InitialContext getInitialContext(Hashtable<String, String> props){
        javax.naming.InitialContext ctx = null;
        if(props != null){
            try {
                ctx = new javax.naming.InitialContext(props);
             }
             catch (NamingException ne) {
               System.out.println("Failed to create JNDI context from server");
             }
        }else{
            try {
                ctx = new javax.naming.InitialContext();
             }
             catch (NamingException ne) {
               System.out.println("Failed to create JNDI context from server");
             }
        }
        return ctx;
    }

    public UserTransaction getUserTransaction() throws TransactionException{
        javax.naming.InitialContext initialContext = getInitialContext(null);
        // try to get one from JNDI
        try {
            return (UserTransaction)initialContext.lookup("java:comp/UserTransaction");
        } catch (NamingException e) {
            throw new TransactionException(e); <===== exception here
        }
   }

client app :
        try {
            usertx = txm.getUserTransaction();
        } catch (TransactionException e) {
            e.printStackTrace(System.out);
        }
        usertx.begin();

Error is:
 javax.naming.NameNotFoundException: No object bound for java:comp/UserTransaction [Root exception is java.lang.NullPointerException]

My question is:
1. This is normal stuff. Anyone has done this on glassfish? which version? Nightly build? What did I do wrong?
2. I didn't pass anything to initialContext, should I?
3. Know bugs or solutions?

thanks

ying
[Message sent by forum member 'yxd0018' (yxd0018)]

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