-->
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: NoInitialContextException with Hibernate Tools reverse eng.
PostPosted: Fri Jan 11, 2008 12:39 pm 
Newbie

Joined: Fri Jan 11, 2008 12:23 pm
Posts: 2
Eclipse version: 3.3.0
Hibernate version: 3.2.5
Hibernate Tools version: 3.2.0

Mapping documents:

Code:
<?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="CmppSessionFactory">
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">campaign</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@192.168.14.53:1521:Preora10</property>
        <property name="hibernate.connection.username">campaign</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
       
        <mapping resource="it/ribes/cmpp/hibernate/UsersDl196.hbm.xml" />
    </session-factory>
   
</hibernate-configuration>


Full stack trace of any exception that occurs:

Code:
11-gen-2008 17.13.11 it.ribes.cmpp.hibernate.UsersDl196Home getSessionFactory
GRAVE: 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 it.ribes.cmpp.hibernate.UsersDl196Home.getSessionFactory(UsersDl196Home.java:28)
   at it.ribes.cmpp.hibernate.UsersDl196Home.<init>(UsersDl196Home.java:23)
   at it.ribes.cmpp.test.TestHibernate.<init>(TestHibernate.java:11)
   at it.ribes.cmpp.test.TestHibernate.main(TestHibernate.java:22)
Exception in thread "main" java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
   at it.ribes.cmpp.hibernate.UsersDl196Home.getSessionFactory(UsersDl196Home.java:31)
   at it.ribes.cmpp.hibernate.UsersDl196Home.<init>(UsersDl196Home.java:23)
   at it.ribes.cmpp.test.TestHibernate.<init>(TestHibernate.java:11)
   at it.ribes.cmpp.test.TestHibernate.main(TestHibernate.java:22)



Name and version of the database you are using: Oracle 10g rel 2


Hello, I'm trying to access a Oracle database using the eclipse hibernate tools generated classes. But I get the reported exception when the Home try to access to the sessionfactory.

any help is appreciated!

This is my home class:
Code:
package it.ribes.cmpp.hibernate;

// Generated 11-gen-2008 13.51.42 by Hibernate Tools 3.2.0.CR1

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import static org.hibernate.criterion.Example.create;

/**
* Home object for domain model class UsersDl196.
* @see it.ribes.cmpp.hibernate.UsersDl196
* @author Hibernate Tools
*/
public class UsersDl196Home {

   private static final Log log = LogFactory.getLog(UsersDl196Home.class);

   
   private final SessionFactory sessionFactory = getSessionFactory();

   protected SessionFactory getSessionFactory() {
      try {
         return (SessionFactory) new InitialContext()
               .lookup("SessionFactory");
      } catch (Exception e) {
         log.error("Could not locate SessionFactory in JNDI", e);
         throw new IllegalStateException(
               "Could not locate SessionFactory in JNDI");
      }
   }

   public void persist(UsersDl196 transientInstance) {
      log.debug("persisting UsersDl196 instance");
      try {
         sessionFactory.getCurrentSession().persist(transientInstance);
         log.debug("persist successful");
      } catch (RuntimeException re) {
         log.error("persist failed", re);
         throw re;
      }
   }

   public void attachDirty(UsersDl196 instance) {
      log.debug("attaching dirty UsersDl196 instance");
      try {
         sessionFactory.getCurrentSession().saveOrUpdate(instance);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public void attachClean(UsersDl196 instance) {
      log.debug("attaching clean UsersDl196 instance");
      try {
         sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public void delete(UsersDl196 persistentInstance) {
      log.debug("deleting UsersDl196 instance");
      try {
         sessionFactory.getCurrentSession().delete(persistentInstance);
         log.debug("delete successful");
      } catch (RuntimeException re) {
         log.error("delete failed", re);
         throw re;
      }
   }

   public UsersDl196 merge(UsersDl196 detachedInstance) {
      log.debug("merging UsersDl196 instance");
      try {
         UsersDl196 result = (UsersDl196) sessionFactory.getCurrentSession()
               .merge(detachedInstance);
         log.debug("merge successful");
         return result;
      } catch (RuntimeException re) {
         log.error("merge failed", re);
         throw re;
      }
   }

   public UsersDl196 findById(java.math.BigDecimal id) {
      log.debug("getting UsersDl196 instance with id: " + id);
      try {
         UsersDl196 instance = (UsersDl196) sessionFactory
               .getCurrentSession().get(
                     "it.ribes.cmpp.hibernate.UsersDl196", id);
         if (instance == null) {
            log.debug("get successful, no instance found");
         } else {
            log.debug("get successful, instance found");
         }
         return instance;
      } catch (RuntimeException re) {
         log.error("get failed", re);
         throw re;
      }
   }

   public List<UsersDl196> findByExample(UsersDl196 instance) {
      log.debug("finding UsersDl196 instance by example");
      try {
         List<UsersDl196> results = (List<UsersDl196>) sessionFactory
               .getCurrentSession().createCriteria(
                     "it.ribes.cmpp.hibernate.UsersDl196").add(
                     create(instance)).list();
         log.debug("find by example successful, result size: "
               + results.size());
         return results;
      } catch (RuntimeException re) {
         log.error("find by example failed", re);
         throw re;
      }
   }
}



This is my test code:
Code:
   public TestHibernate() {
      UsersDl196Home userHome = new UsersDl196Home();
      UsersDl196 user = userHome.findById(new BigDecimal(47));
      
      System.out.println(user.getUsername());
   }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Code is using JNDI to find the SessionFactory. The error is saying the JNDI is not configured so it leaves the question - How have you deployed this code?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 3:57 am 
Newbie

Joined: Fri Jan 11, 2008 12:23 pm
Posts: 2
Yeah I understood that, How can I configure the JNDI in the following environments?

- JBoss
- Java standalone


Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 6:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
JBoss - use the JMX deployer, e.g, har package (see JBoss documentation online).
Java - Might choose to not use JNDI and get session from the factory directly.


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.