-->
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.  [ 2 posts ] 
Author Message
 Post subject: Transaction Management PROBLEM with Glassfish
PostPosted: Tue Mar 31, 2009 4:34 am 
Newbie

Joined: Tue Mar 31, 2009 4:27 am
Posts: 2
Hello, I'm using hibernate 3 with Glassfish 2.1

I'm having some issues with transactions, according to Hibernate documentation, the use of org.hibernate.transaction.JTATransactionFactory lets Hibernate to check weather a Container Managed Transaction is running and if so relying on that, otherwise creates a new transaction (looking up for java:comp/UserTransaction).
my code is something like:

Code:
Transaction tx = null;
try {
   
    tx = factory.getCurrentSession().beginTransaction();

    // Do some work
    factory.getCurrentSession().load(...);
    factory.getCurrentSession().persist(...);

    tx.commit();
}
catch (RuntimeException e) {
    tx.rollback();
    throw e;
}

This is inside an EJB 3 method. If I try to run this code, I got the following exception:

Code:
javax.naming.NameNotFoundException:
Lookup of java:comp/UserTransaction not allowed for Container managed Transaction beans at com.sun.ejb.containers.BaseContainer.checkUserTransactionLookup(BaseContainer.java:691)
        at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:190)
        at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:396)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)


So it looks like bean is under Container Manager Transaction. Why Hibernate doesn't detect this and creates a new transaction?

Following the hibernate documentation, I tried to switch to org.hibernate.transaction.CMTTransactionFactory
which should rely on existing CMT. I changed my code to something like:

Code:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void doSomeWork() {
    // Do some work
    factory.getCurrentSession().load(...);
    factory.getCurrentSession().persist(...);
}


So I let the container to manager the transaction, but if I try to save some simple object via hibernate, nothing is written to the DB, thus I guess there's no transaction.commit() executed.

The only way to let it work is to use
org.hibernate.transaction.CMTTransactionFactory and switch back to explicit transaction handling (first code sample) but this is not in accordance with documentation.

Any help would be really appreciated.

Stefano Emiliozzi


Last edited by thepomy on Wed Jul 15, 2009 10:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Transaction Management with Glassfish
PostPosted: Wed Jul 15, 2009 10:18 am 
Newbie

Joined: Tue Mar 31, 2009 4:27 am
Posts: 2
Up


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.