I'm new to hibernate. I'm running hibernate 4.1.3 and Tomcat 7.0.27
I'm auto-generating DAO's with hibernate, and these DAO's contain this code:
Code:
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");
}
}
My hibernate config contains this:
Code:
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/myDB</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">20</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
I'm receiving this error:
Code:
SEVERE: Could not locate SessionFactory in JNDI
javax.naming.NameNotFoundException: Name [SessionFactory] is not bound in this Context. Unable to find [SessionFactory].
I would like to leave the DAO's as they were created, without modification.
How do I configure my application so that it finds the default SessionFactory?
Any help would be appreciated, thanks!