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 2Hello, 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());
}