-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Could not locate SessionFactory in JNDI
PostPosted: Wed Jul 06, 2011 6:18 am 
Newbie

Joined: Wed Jul 06, 2011 6:05 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.