-->
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.  [ 5 posts ] 
Author Message
 Post subject: Naming Service and Hibernate
PostPosted: Tue Jul 31, 2007 5:22 am 
Newbie

Joined: Fri Apr 13, 2007 6:56 am
Posts: 3
Hi all.
I'm trying to develop a standalone application using Java Swing and interfacing Oracle with Hibernate.
Now I have a problem. How can I use name service for accessing to SessionFactory? I thought about using JNDI, but i have problems to configure InitialContext.
First of all, JNDI is a right solution for my problem?
And then how can I configure InitialContext?
Thanks for your replies


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 3:27 pm 
Newbie

Joined: Fri Apr 13, 2007 6:56 am
Posts: 3
Up!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 3:35 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
Context initialCntx = new InitialContext();
SessionFactory sessionFactory = (SessionFactory)initialCntx.lookup("java:comp/env/hibernate/SampleSessionFactory");
Session hibernateSess = sessionFactory.getCurrentSession();

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 1:10 pm 
Newbie

Joined: Fri Apr 13, 2007 6:56 am
Posts: 3
Thanks for your answer. But the problem still remains.
My trouble is before.
I've seen in some tutorial on the web that i must configure hibernate.cfg.xml
with these parameters:
Code:
<session-factory name="a name">
        <property name="hibernate.jndi.url"></property>
        <property name="hibernate.jndi.class"></property>

But which values can i insert for "hibernate.jndi.url" and "hibernate.jndi.class"?
I don't understand. Please help me!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 1:28 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
we posted the exact same thing, only mine is implemented in java code and yours is implemented in an xml configuration file to be loaded by Spring or some other container.

Use the jndi name (url) as the url.

Optionally, you may define the initialContext class with that hibernate.jndi.class term. You don't have to.

Then in your program when you call Configuration.buildSessionFactory() your session factory will use that jndi connection to obtain database connections.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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