-->
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: InitialContext Exception
PostPosted: Thu May 10, 2007 10:00 pm 
Newbie

Joined: Fri May 04, 2007 1:48 pm
Posts: 7
Hi,

I am trying to write a simple Hibernate code.
I am getting the following exception:

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(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:291)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at com.sample.employee.LoadEmployees.main(LoadEmployees.java:9)
May 10, 2007 9:46:31 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute




Following is my source code:

public class LoadEmployees
{
public static void main(String args[])
{
SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();
session.beginTransaction();
Employee emp = new Employee();
emp.setEmployeeId(1);
emp.setEmployeeName("Balaji");
session.save(emp);
session.getTransaction().commit();
session.close();
}
}


Following is my hibernate config file:

<hibernate-configuration>
<session-factory name="TweSessionFactory">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@zeus1dev:1521:zeusdev</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.username">olga_twe48_lease</property>
<property name="hibernate.connection.password">olga_twe48_lease</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="current_session_context_class">thread</property>
<mapping resource="Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Following is my hbm file

<hibernate-mapping>
<class name="com.sample.employee.Employee" table="EMPLOYEE_DETAILS">
<id name="employeeId" type="long" column="EMPLOYEE_ID" >
<generator class="assigned"/>
</id>

<property name="employeeName">
<column name="EMPLOYEE_NAME" />
</property>
</class>
</hibernate-mapping>


Any of you have any idea of what the exception is about.

Thanks,
Balaji


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 1:43 am 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Do you need to bind the SessionFactory to JNDI?

If not remove the name attribute from session-factory element. It should work.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 9:28 am 
Newbie

Joined: Fri May 04, 2007 1:48 pm
Posts: 7
Thanks. That did work.


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.