-->
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.  [ 12 posts ] 
Author Message
 Post subject: Transaction managment in Weblogic
PostPosted: Wed Mar 17, 2004 4:26 am 
Newbie

Joined: Fri Feb 13, 2004 7:59 am
Posts: 8
Location: Gavle, Sweden
Hi,
I have a problem with managing transaction from a stateless EJB in weblogic. I have a weblogic startup class where i bind a sessionfactory to the JNDI-tree. The configuration is as follows:
Configuration cfg = new Configuration()
.addClass(IMArende.class)
.addClass(...)
.addClass(...)
.addClass(...)
.addClass(Varning.class);

cfg.setProperty("hibernate.dialect",
"net.sf.hibernate.dialect.Oracle9Dialect"); cfg.setProperty("hibernate.transaction.factory_class",
"net.sf.hibernate.transaction.JTATransactionFactory");
cfg.setProperty("hibernate.transaction.manager_lookup_class",
"net.sf.hibernate.transaction.WeblogicTransactionManagerLo okup");

SessionFactory factory = cfg.buildSessionFactory();

From my session bean, I fetch a session from a class where I keep the session in a ThreadLocal. The connection for the session is obtained from the connection pool in weblogic:

public class HibernateUtil {

private static final SessionFactory sessionFactory;
private static ServiceLocator locator;


static {
try{
locator = ServiceLocator.getInstance();
sessionFactory = (SessionFactory) locator.getObject("hibernate");
}
}
public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
System.out.println("Trying to open session in hibernateutil");

try {
Connection connection = locator.getDataSource ("ihanDS").getConnection();
s = sessionFactory.openSession(connection);
}
catch (NamingException ex) {
ex.printStackTrace();
throw new RuntimeException("Exception trying to find ihanDS: " + ex.getMessage(), ex);
}
catch (SQLException ex) {
ex.printStackTrace();
throw new RuntimeException("Exception trying to obtain connection: " + ex.getMessage(), ex);
}
System.out.println("Succesfully opened session in hibernateutil");
session.set(s);
}
return s;
}

}
My problem is that inside the CMP bean I dont want to use Hibernates Transaction API. Instead I want to use Weblogics CMT, but doing this no data is committed to the DB (which is an Oracle 9.2.1 by the way) and no exception is raised either.
My code in the sesion bean looks like this:

session = HibernateUtil.currentSession();
session.beginTransaction();
System.out.println("Fick tag p


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 10:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you should set jta.UserTransaction and remove the extra spave between the 2 o of "net.sf.hibernate.transaction.WeblogicTransactionManagerLo okup"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:06 am 
Newbie

Joined: Fri Feb 13, 2004 7:59 am
Posts: 8
Location: Gavle, Sweden
Thanks for your reply,
I have tried to set the jta.UserTransaction but it didnt work either.
In the hibernate properties file it says that it is not necessary to set the jta.UserTransaction property if a transactionmanagerlookup class is specified.


Hibernate properties:
"
## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
## default is java:comp/UserTransaction
## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class

#jta.UserTransaction jta/usertransaction
#jta.UserTransaction javax.transaction.UserTransaction
#jta.UserTransaction UserTransaction
"

And the Xtra space beetween the 2 o's is not in my code, its just there cause I was a bit sloppy when I cut & pasted & tried to make the code look nice in my message..

/Henrik


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Oh, you"re using a Weblogic datasource, not the JDBC diriver directly, are you ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:30 am 
Newbie

Joined: Fri Feb 13, 2004 7:59 am
Posts: 8
Location: Gavle, Sweden
Yes, thats correct!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
And you DS is a TxDatasource.
This should work (it is for me actually).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 6:12 am 
Newbie

Joined: Fri Feb 13, 2004 7:59 am
Posts: 8
Location: Gavle, Sweden
Yes, its a TxDataSource.
It seems that my connection, obtained from Weblogic, wont commit. If I try to do session.connection().commit() I get an exception thats says that I cant commit a distributed transaction.
If I do session.close().close() I get no exception but still no data is committed to the DB.

/Henrik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 5:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, I really don't think it's Hibernate related. Try to do a plain JDBC call (takingconenction from your TxDS) and reproduce the problem.
Do you use several DS in this Tx? 2PC issue?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Transaction managment using CMT
PostPosted: Fri Mar 19, 2004 7:16 am 
Newbie

Joined: Fri Mar 12, 2004 10:02 am
Posts: 16
You might try a session.flush().

I had the same problem using JBoss. I think we should figure out some examples, one Session Bean using CMT and some howtos which describe which methods to use and which to avoid.

I doubt that Hibernate creates an error when I manually commit using CMT. This will defenitly destroy the CMT and result in unpredictable results.

I think there are different configuration options which should have an example too.

Haug


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 3:59 am 
Newbie

Joined: Fri Feb 13, 2004 7:59 am
Posts: 8
Location: Gavle, Sweden
Session.flush() solved the problem.
This really helps me out heaps.
Thanks to both of you for taking time to help me out!
Regards Henrik


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 4:29 pm 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
Why doesn't Hibernate call flush automatically when you close a session? It seems to break some abstraction between Hibernate and the code that uses it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
-1
I use this capability to update and not persist objets that I give to the upper layer.

_________________
Emmanuel


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