-->
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: How to lookup hibernate jndi?
PostPosted: Fri Nov 28, 2003 9:13 pm 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Hello gavin,

Dear Sir,

Could you be kind enough to teach me how to access the hibernate jndi
java:/hibernate/HibernateFactory using the correct jndi lookup or method?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 9:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
eh?

I have no idea. I don't know anything about your appserver and unless its WebSphere I wouldn't have a clue anyway.

Please don't address questions to me directly - there are lots of other people in the forum who will be much better equipped to help you if you give sufficient information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 9:34 pm 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Hi,


application server is jboss-3.2.2 , does this helps?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 29, 2003 2:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
In your SAR or JMX deployment service descriptor you will have a line similar to this (This is what I have).

<attribute name="JndiName">java:/HibernateFactory<attribute>

In you EJB code (SLSB/DAOs) you will have to lookup the JNDI name. eg.

InitialContext context = new InitialContext();
SessionFactory factory = (SessionFactory) context.lookup("java:/HibernateFactory");

Thats all that is needed. There is information on JBoss and Hibernate in the Wiki and a number of examples exist aswell.


Top
 Profile  
 
 Post subject: Not sure about JBoss, but for Tomcat, you can do JNDI ....
PostPosted: Sat Nov 29, 2003 2:20 am 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
I use a hibernate.cfg.xml file and specify my session-factory as (using your given JNDI name, mine would be without that first slash):

=-=-=-==-=-=-==-=-=-==-=-=-==-=-=-=
<session-factory name="java:/hibernate/HibernateFactory">
...
</session-factory>
=-=-=-==-=-=-==-=-=-==-=-=-==-=-=-=

To perform the lookups for the session factory, I do the following calls:

=-=-=-==-=-=-==-=-=-==-=-=-==-=-=-=
import javax.naming.Context;
import javax.naming.InitialContext;

try {
String jndiLocation = "java:/hibernate/HibernateFactory";
Context ctx = new InitialContext();
SessionFactory sf = (SessionFactory) ctx.lookup(jndiLocation);
Session session = sf.openSession();

} catch ( NamingException ne ) {
// do something here (up to you)
} catch ( HibernateException he ) {
// do something else here (up to you)
}

=-=-=-==-=-=-==-=-=-==-=-=-==-=-=-=

That's it. I don't modify my server.xml, web.xml or anything else. I take the lazy road and let hibernate initialize everything when I setup the configuration the first time.

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 4:41 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
hello -
i am new to hibernate and have encountered a similiar problem, which 66.html fixed for me. however, this quote:

Quote:
That's it. I don't modify my server.xml, web.xml or anything else. I take the lazy road and let hibernate initialize everything when I setup the configuration the first time.


is something that has me a bit confused. since i have packed up hibernate in a SAR mbean do i still need to setup a configuration file as well? the docs are very clear on this.

thanks,
jason


Top
 Profile  
 
 Post subject: To server.xml or not to server.xml with JNDI?
PostPosted: Sun Jan 04, 2004 4:47 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Jason,

Since making my post, I've found out that if you don't modify the server.xml file but simply use a hibernate.cfg.xml with <session-factory name="some:jndi/name" ... /> then you end up with a JNDI instance that you can only access from that local webapp. If you need to share your hibernate sessionFactory between webapps, you will need to modify your server.xml file.

Personally, I haven't mixed webapps to all use the same hibernate SessionFactory, so this isn't an issue for me, yet.

Regards,
David


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.