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
|