-->
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.  [ 3 posts ] 
Author Message
 Post subject: Jboss 3.2.6 JNDI access from hibernate
PostPosted: Fri Oct 22, 2004 10:07 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
Hi,
I have just migrated from Apache/Tomact to Apache/Jboss 3.2.6 and now need to change my class files to take advantage of JNDI. I have declared my jndi:

[SessionFactoryObjectFactory] Factory name: java:/HibernateFactory

What I am not to clear about is how to now access a transaction via jndi from java code? This is how my classes currently access a transaction:

session = HibernateUtil.currentSession();
transaction = session.beginTransaction();

but could I now acces a transaction like so?:

Context ctx = new InitialContext();
UserTransaction ut = (UserTransaction)ctx.lookup("java:/HibernateFactory");
ut.begin();
ut.commit();

How would I close the session? ut.closeSession()?

many thanks


Uzo


Top
 Profile  
 
 Post subject: Ok...i've taken this as far as I can
PostPosted: Fri Oct 22, 2004 8:14 pm 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
and would really appreciate some help here. I have amended my class file as so:

import org.jboss.hibernate.session.HibernateContext;
import org.jboss.tm.TransactionLocal;
import net.sf.hibernate.*;

...........

Session session = HibernateContext.getSession("java:/HibernateFactory");


try {
//Util = new HibernateUtil();
//session = Util.currentSession();

transaction = session.beginTransaction();
//Get User details
Query query = session.createQuery("from test.User as user where user.UserName=:username and user.UserPassword=:password")
.setString("username",username)
.setString("password",password);
user = (User) query.uniqueResult();

transaction.commit();
//Util.closeSession();

} catch (HibernateException e) {

throw new RuntimeException("Exception in Hibernate:: " + e.getMessage(), e);
}

When I call the method no data is being returned and I get the following output in the logs:

2004-10-23 01:09:52,014 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: HibernateFactory
2004-10-23 01:09:52,015 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=d1e22501ffc2fc8300ffc2fc87990000
2004-10-23 01:09:52,015 DEBUG [net.sf.hibernate.impl.SessionImpl] opened session
2004-10-23 01:09:52,134 INFO [org.apache.jk.server.JkCoyoteHandler] Response already commited
2004-10-23 01:09:52,151 INFO [org.apache.jk.server.JkCoyoteHandler] Response already commited
2004-10-23 01:09:52,187 INFO [org.apache.jk.server.JkCoyoteHandler] Response already commited

many thanks


Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 10:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Don't really understand what you are asking for here. You just want to know how to retreive the UserTransaction directly from JBoss JNDI? It is stored under "java:/UserTransaction" as outlined in the JBoss docs.


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