I use reverse engineering capabilities built into the hibernate eclipse plugin to generate dao and hbm.xml files for each table.
It does it pretty well, but when I try to use the generated objects, I get I can not find the SessionFactory in the JNDI error.
I saw a message that suggested that this happens when you call your SessionFactory in the hibernate.cfg.xml file, so I removed the name tag and I still get the same error.
This is 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> <property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">qwerty</property> <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/agilegroup3</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.default_catalog">agilegroup3</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> <mapping resource="generated/Usersroles.hbm.xml" /> <mapping resource="generated/Role.hbm.xml" /> <mapping resource="generated/Logdata.hbm.xml" /> <mapping resource="generated/Logtrigger.hbm.xml" /> <mapping resource="generated/User.hbm.xml" /> </session-factory> </hibernate-configuration>
This is the generated code that throws the exception.
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"); } }
I am not very versed in JNDI, but I think that some kind of search is equivalent to a configuration file. I do not want to use JNDI, but I do not know how to achieve this using the eclipse pluggin.
Changing the generated code will not help me, because I will need to continue to restore it at some points, so if anyone can explain why and how this happens, and what I can do about it, I would be grateful
thanks
Jonathan
source share