-->
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.  [ 4 posts ] 
Author Message
 Post subject: Getting javax.naming.NoInitialContextException
PostPosted: Sat Apr 28, 2007 9:55 am 
Newbie

Joined: Thu Nov 02, 2006 11:23 pm
Posts: 4
Hi All:

I have used reveng.xml to generate DAO and VO Code for my Hibernate and Struts 1.2 Application within Eclipse 3.2 Using JBoss Hibernate Plugins.

However, my DAO Code is Useless as the following fails:

protected SessionFactory getSessionFactory()
{
try
{

return (SessionFactory) new InitialContext().lookup("java:comp/env/hibernate/SessionFactory");
}
catch (Exception e)
{
log.error("********Could not locate SessionFactory in JNDI", e);

}

return null;
}


I get the Following Exception:

SEVERE: ********Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.dict.dao.WordMasterHome.getSessionFactory(WordMasterHome.java:36)
at com.dict.dao.WordMasterHome.<init>(WordMasterHome.java:29)


The following is my hibernate.cfg.xml File

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="SessionFactory">
<property name="hibernate.session_factory_name">java:comp/env/hibernate/SessionFactory</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dictionary</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.default_schema">dictionary</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/dict/dao/PartOfSpeechMaster.hbm.xml" />
<mapping resource="com/dict/dao/MeaningMaster.hbm.xml" />
<mapping resource="com/dict/dao/WordMaster.hbm.xml" />
</session-factory>
</hibernate-configuration>


which was also generated using the Plugins.

I am not able to get a Sessin Factory. This is so puzzling. Do I need a context.xml in META_INF or what ????

All help is appreciated.

Thanks.

Chetan






Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 29, 2007 5:51 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
What server are you running this in? If you're using Tomcat, you won't be able to manage the SessionFactory using JNDI because the tomcat JNDI implementation is read-only. In that case, remove the jndi line from your config file and build it manually. Very simple to do and very well documented.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 4:32 am 
Newbie

Joined: Thu Nov 02, 2006 11:23 pm
Posts: 4
Dear Mr. cbredsen:

Thanks for your Kind Reply.

Yes I am using Tomcat 5.5

So do you mean to say I should comment the following from hibernate.cfg.xml

<property name="hibernate.session_factory_name">java:comp/env/hibernate/SessionFactory</property>

As for building it manually, will you pls direct me to resources where I can do so.

As this later part is a little Unclear to me.

Thanks

Chetan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 7:59 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Yes that line needs to go. Hibernate will attempt to bind itself there and it will fail. You also won't be able to lookup SessionFactory in JNDI. This section of the docs will help you greatly:

http://www.hibernate.org/hib_docs/refer ... start.html

-Chris


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