EDIT: Solved! See below, in the next message.
I have the same problem but with your steps i'm unable to solve. My settings:
hibernate.cfg.xml
Code:
<session-factory>
<property name="jndi.class">com.sun.jndi.fscontext.RefFSContextFactory</property>
<property name="jndi.url">file:///tmp</property>
<property name="hibernate.session_factory_name">hibernate/HibernateFactory</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/model</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">2</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">false</property>
<mapping resource="config.hbm.xml"/>
</session-factory>
A session initializated somewhere with:
Code:
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
A similar dao class
(here is the problem!!!!):
Code:
protected SessionFactory getSessionFactory() {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
return (SessionFactory) new InitialContext(env).lookup("hibernate/HibernateFactory");
}
catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException("Could not locate SessionFactory in JNDI");
}
}
The jndi context seems created (/tmp/hibernate/.bindings)
Code:
#This file is used by the JNDI FSContext.
#Tue Mar 20 01:23:07 CET 2007
HibernateFactory/RefAddr/0/Content=ff808181116cb9ca01116cb9cd760000
HibernateFactory/FactoryName=org.hibernate.impl.SessionFactoryObjectFactory
HibernateFactory/ClassName=org.hibernate.impl.SessionFactoryImpl
HibernateFactory/RefAddr/0/Encoding=String
HibernateFactory/RefAddr/0/Type=uuid
But
Still i get this errors:
Code:
[java] 01:23:07,947 WARN SessionFactoryObjectFactory:101 - InitialContext did not implement EventContext
[java] 01:23:07,963 ERROR ProvinciaHome:33 - Could not locate SessionFactory in JNDI
[java] javax.naming.NameNotFoundException: HibernateFactory
[java] at com.sun.jndi.fscontext.RefFSContext.getObjectFromBindings(RefFSContext.java:419)
[java] at com.sun.jndi.fscontext.RefFSContext.lookupObject(RefFSContext.java:347)
[java] at com.sun.jndi.fscontext.RefFSContext.lookup(RefFSContext.java:183)
[java] at com.sun.jndi.fscontext.FSContext.lookup(FSContext.java:165)
[java] at javax.naming.InitialContext.lookup(InitialContext.java:347)
[java] at com.thgroup.visionehrcv.model.ProvinciaHome.getSessionFactory(ProvinciaHome.java:30)
[java] at com.thgroup.visionehrcv.model.ProvinciaHome.<init>(ProvinciaHome.java:24)
[java] at com.thgroup.visionehrcv.model.util.VisioneHRCVUtil.popolaDB(VisioneHRCVUtil.java:63)
[java] at com.thgroup.visionehrcv.model.util.VisioneHRCVUtil.main(VisioneHRCVUtil.java:40)
[java] Exception in thread "main" java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
[java] at com.thgroup.visionehrcv.model.ProvinciaHome.getSessionFactory(ProvinciaHome.java:34)
[java] at com.thgroup.visionehrcv.model.ProvinciaHome.<init>(ProvinciaHome.java:24)
[java] at com.thgroup.visionehrcv.model.util.VisioneHRCVUtil.popolaDB(VisioneHRCVUtil.java:63)
[java] at com.thgroup.visionehrcv.model.util.VisioneHRCVUtil.main(VisioneHRCVUtil.java:40)
[java] Java Result: 1
Please, help me. I can't go forward until i i get this to work :-(