I've been searching through various problems trying to solve the below error, to no success with the recommended strategies. I'm using the hibernate eclipse plugin and performing the reverse object creation from a reveng.xml file, and at one point not that long ago, everything was working fine - a few changes (that weren't hibernate related!) later, and I now get the below issue. I'm relatively certain it has to be some sort of configuration issue, I just can't figure out what:
Error: SEVERE: 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(Unknown Source)
I have no desire to have a specific session factory or use specify JNDI, and per the posts I've seen, you just don't put in the session-factory name in your config file -- which I've done (and had previously already):
<?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> <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">letmein</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/wwa</property> <property name="hibernate.connection.username">test</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <mapping resource="com/brighttiger/wwa/data/client/Program.hbm.xml" /> <mapping resource="com/brighttiger/wwa/data/client/Collection.hbm.xml" /> </session-factory> </hibernate-configuration>
The DAO object created the following code to perform the following to create the session:
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"); } }
Looking up the new initial context is where everything goes haywire at. Additionally, I can configure and successfully use the hibernate console in eclipse to perform HQL queries/etc without issue. This leaves me at a dead end as to just what it is I broke along the way. Any help is appreciated, thanks!
|