-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: JBoss 3.2.1 Could not find UserTransaction in JNDI
PostPosted: Sat Aug 30, 2003 6:11 am 
Newbie

Joined: Sat Aug 30, 2003 5:46 am
Posts: 5
On Friday, I decided it was time to play with JBoss and Hibernate.
So I took a small portion of my working Hibernate2 GUI app and with a little cut n paste created a stateless session bean, which contains my hibernate code.


The trouble im having, and this maybe due to my lack of understanding, is with transactions.

In my GUI app I have many funtions that resemble
Code:
void someBusinessMethod( ) {

    Session session = getSession();
    tx = session.beginTransaction();
        /// HACK THE DB.
    tx.commit();
}


I have converted these to session bean functions that look like
Code:
    /** Create a new Purchase Order, with one line item for the specified part.
     * Creates a new Purchase Orders. Then adds a single line item with a
     * quantity of 1, for the specified supplier part.
     *
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="Required"
     *
     * @param supplierPartID The ID of the supplier part.
     * @return The ID for the new PurchaseOrder.
     */
    public Long newPurchaseOrder( Long supplierPartID ) throws PurchaseOrderDBException, NamingException {
        System.out.println("+++++++++++++++ newPurchaseOrder");
        long startTime = System.currentTimeMillis();
        PurchaseOrderDTO theOrder = new PurchaseOrderDTO();
       
        Session s = null;
        Transaction tx = null;
        try {
            s = openSession();
            System.out.println("+++++++++++++++ newPurchaseOrder openSession OK" );
            tx = s.beginTransaction();
            System.out.println("+++++++++++++++ newPurchaseOrder beginTransaction OK");



When I run this in my Session bean, I always get
Code:
10:38:57,451 ERROR [JTATransaction] Could not find UserTransaction in JNDI
javax.naming.NameNotFoundException: UserTransaction not bound
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
        at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
        at org.jnp.server.NamingServer.lookup(NamingServer.java:282)

When I call s.beginTransaction()



After much googling the only thread I could find mentioning this error, was because the guy was using HiLo Key gen. Im using postgres sequences.
http://www.mail-archive.com/jboss-user@ ... 23649.html


Im using Hibernate via JMX
Code:
jboss-service.xml
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
                            name=HibernateFactory">
    <depends>jboss.jca:service=RARDeployer</depends>
    <depends>jboss.jca:service=LocalTxCM,name=StarjarCRMDS</depends>


    <classpath codebase='.' archives='starjarcrmdb.jar' />
   
    <!-- Make it deploy ONLY after DataSource had been started -->
    <attribute name="MapResources">
mappings/PurchaseOrderDTO.hbm.xml
    </attribute>
    <attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
    <attribute name="Datasource">java:/StarjarCRMDS</attribute>
    <attribute name="Dialect">net.sf.hibernate.dialect.PostgreSQLDialect</attribute>
    <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
    <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
    <attribute name="UseOuterJoin">false</attribute>
    <attribute name="ShowSql">false</attribute>
    <attribute name="UserTransactionName">java:/UserTransaction</attribute>
</mbean>
</server>


Note I've also tried
<attribute name="UserTransactionName">java:comp/UserTransaction</attribute>
which makes no difference.





Am I completely missing the point with Transactions in EJB land, or do I still need to start and commit/rollback transaction as I do in my none ejb app?

Any help is appreciated.



Peter Henderson.




Just in case its needed, The mapping file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

        <class name="com.starjar.crm.database.PurchaseOrderDTO"
               table="purchaseorders" 
               proxy="com.starjar.crm.database.PurchaseOrderDTO"
        >
            <id name="ID" column="ID" unsaved-value="null">
                <generator class="sequence">
                    <param name="sequence">purchaseorders_id_seq</param>
                </generator>
            </id>
            <version column="Version" name="Version" type="int" />           

            <many-to-one name="Company" column="CompanyID" not-null="true"/>
            <property name="Status" />

             <!-- more fields here -->
           
        </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 8:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
Am I completely missing the point with Transactions in EJB land, or do I still need to start and commit/rollback transaction as I do in my none ejb app?


Correct, you should not have that call to s.beginTransaction() in your code.

The error you get is interesting however. What happens if you manually try to look up the UserTransaction from JNDI? Can your code find it? Try something like
Code:
System.out.println( "Got txn : " + new InitialContext().lookup( "java:/UserTransaction" );


Is that the full stack trace? What about the lines after?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 9:34 am 
Newbie

Joined: Sat Aug 30, 2003 5:46 am
Posts: 5
Thanks for the feedback.

Looks like I need to do more reading about transactions in EJB. At the moment the thought of removing s.beingTransaction() from my code feels as safe as skating on thin ice ;-)



No thats not the fully stack trace. I thought I could save space and not include it all.

Here it is in full.
Code:
14:23:49,139 ERROR [JTATransaction] Could not find UserTransaction in JNDI
javax.naming.NameNotFoundException: UserTransaction not bound
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
        at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
        at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)
        at net.sf.hibernate.transaction.JTATransaction.begin(JTATransaction.java:96)
        at net.sf.hibernate.transaction.JTATransactionFactory.beginTransaction(JTATransactionFactory.java:80)
        at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1981)
        at com.starjar.ejbtest.PurchaseOrderBean.newPurchaseOrder(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:629)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)

        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)

        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
        at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:322)
        at org.jboss.ejb.Container.invoke(Container.java:674)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
        at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
        at sun.rmi.transport.Transport$1.run(Transport.java:148)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
        at java.lang.Thread.run(Thread.java:534)
14:23:49,154 INFO  [STDOUT] Failure creating new Purchase Order





Also.
When I lookup the UserTransaction as per your suggestiong, using.
Code:
        try {
            System.out.println( "Looking up java:/UserTransaction" );
            System.out.println( "Got txn : " + new InitialContext().lookup( "java:/UserTransaction" ) );
        } catch( Exception e ) {
            System.out.println("ERROR: " + e);
            e.printStackTrace();
        }


It fails with a very similar exception.
Code:
14:23:48,858 INFO  [STDOUT] Looking up java:/UserTransaction
14:23:48,858 INFO  [STDOUT] ERROR: javax.naming.NameNotFoundException: UserTransaction not bound
14:23:48,858 ERROR [STDERR] javax.naming.NameNotFoundException: UserTransaction not bound
14:23:48,858 ERROR [STDERR]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
14:23:48,858 ERROR [STDERR]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
14:23:48,858 ERROR [STDERR]     at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
14:23:48,858 ERROR [STDERR]     at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
14:23:48,858 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
14:23:48,858 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
14:23:48,858 ERROR [STDERR]     at javax.naming.InitialContext.lookup(InitialContext.java:347)
14:23:48,858 ERROR [STDERR]     at com.starjar.ejbtest.PurchaseOrderBean.newPurchaseOrder(Unknown Source)
14:23:48,858 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:23:48,858 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
14:23:48,858 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

14:23:48,858 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:324)
14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionC
ontainer.java:629)
14:23:48,858 ERROR [STDERR]     at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnect
ionInterceptor.java:186)
14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInst
anceInterceptor.java:72)
14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)

14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)

14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
14:23:48,858 ERROR [STDERR]     at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderIntercep
tor.java:122)
14:23:48,873 ERROR [STDERR]     at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java
:322)
14:23:48,873 ERROR [STDERR]     at org.jboss.ejb.Container.invoke(Container.java:674)
14:23:48,873 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:23:48,873 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
14:23:48,873 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

14:23:48,873 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:324)
14:23:48,873 ERROR [STDERR]     at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java
:284)
14:23:48,873 ERROR [STDERR]     at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
14:23:48,873 ERROR [STDERR]     at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
14:23:48,873 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:23:48,873 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
14:23:48,873 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

14:23:48,873 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:324)
14:23:48,873 ERROR [STDERR]     at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
14:23:48,873 ERROR [STDERR]     at sun.rmi.transport.Transport$1.run(Transport.java:148)
14:23:48,873 ERROR [STDERR]     at java.security.AccessController.doPrivileged(Native Method)
14:23:48,873 ERROR [STDERR]     at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
14:23:48,873 ERROR [STDERR]     at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
14:23:48,873 ERROR [STDERR]     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
14:23:48,873 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:534)





Thanks again for your help.


Peter Henderson.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 9:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Then that is not the JNDI bind name of the UserTransaction. Check out the JBoss docs for what this should be...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 1:02 pm 
Newbie

Joined: Sat Aug 30, 2003 12:39 pm
Posts: 4
steve wrote:
Then that is not the JNDI bind name of the UserTransaction. Check out the JBoss docs for what this should be...


He is using CMT so there is no java:/UserTransaction

Regards,
Adrian

_________________
xxxxxxxxxxxxxxxxxxxxxxxx
Adrian Brock
Director of Support
Back Office
JBoss Group, LLC
xxxxxxxxxxxxxxxxxxxxxxxx


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 3:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
JBoss doesn't make the UserTransaction available when using CMT? I find that hard to believe


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 6:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In the very latest beta release of Hibernate, we can integrate with the TransactionManager, w/o needing to use the UserTransaction.


Unfortunately I actually screwed up the configuration logic so you actually can't take advantage of this feature!

wait for the next release....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.