Hi guys,
I know it's an often asked question, but any past topic fixed my problem.
I used Hibernate Tools, to generate automatically my class, my DAO and my mapping class.
I just tried a simple test to see if it was working :
Code:
ComCompanyHome myComCompanyHome = new ComCompanyHome();
ComCompany myCompany = myComCompanyHome.findById(1);
But it gave me the error
Quote:
Could not locate SessionFactory in JNDI
This is my hibernate.cfg.xml
Code:
<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">admin</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/portail</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.default_schema">portail</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="hibernate.session_factory_name">SessionFactory</property>
</session-factory>
</hibernate-configuration>
And this is what eclipse has created in each DAO class to call the session factory
Code:
private final SessionFactory sessionFactory = getSessionFactory();
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");
}
}
The thing is, I am developing a portlet in Liferay so I just need Hibernate. Im not using spring or struts.
If anyone has an idea ...
Thx,
Cédric