I generated, using hibernate tools 3.1.0 b5 my POJOs and the DAO code.
I really want to give these DAOs a shot, because as far as I understand, I don't need to implement a HibernateUtil class anymore.
Wether I use tomcat or JBoss, I always get a "Could not locate SessionFactory in JNDI" error in the console.
The following line triggers the exception :
return (SessionFactory) new InitialContext()
.lookup("SessionFactory");
I have the following in my Hibernate.cfg.xml :
<?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="SessionFactory">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">***</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cargo?autoReconnect=true</property>
<property name="hibernate.connection.username">***</property>
<property name="hibernate.default_catalog">cargo</property>
<property name="hibernate.default_schema">cargo</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.session_factory_name">java:hibernate/SessionFactory</property> <mapping resource="ch/infolearn/cargo/Crate.hbm.xml" />
<mapping resource="ch/infolearn/cargo/Container.hbm.xml" />
<mapping resource="ch/infolearn/cargo/Company.hbm.xml" />
<mapping resource="ch/infolearn/cargo/Boat.hbm.xml" />
</session-factory>
</hibernate-configuration>
I guess it's something to configure in Tomcat, but I've looked everywhere and just cant find the answer.
See below for more info, and thanks in advance if someone can help.
Hibernate version:
3.0.5
Mapping documents:
the ones generated by default
Code between sessionFactory.openSession() and session.close():
The exception occurs before, on this instruction in the DAO code :
return (SessionFactory) new InitialContext()
.lookup("SessionFactory");
Full stack trace of any exception that occurs:
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
ch.infolearn.cargo.CompanyHome.getSessionFactory(CompanyHome.java:30)
ch.infolearn.cargo.CompanyHome.<init>(CompanyHome.java:22)
org.apache.jsp.db.company_jsp._jspService(org.apache.jsp.db.company_jsp:51)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
Name and version of the database you are using:
mysql 5
The generated SQL (show_sql=true):
n/a
Debug level Hibernate log excerpt:
debug
|