-->
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: hibernate configuration via java code on tomcat
PostPosted: Thu Sep 27, 2007 10:35 am 
Newbie

Joined: Fri Jul 20, 2007 7:04 am
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3

Full stack trace of any exception that occurs:

log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.java.lang.NullPointerException
27/Set/2007 15:18:05 org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
27/Set/2007 15:18:05 org.apache.catalina.core.StandardContext start
SEVERE: Context [/formacao] startup failed due to previous errors


Name and version of the database you are using: MySQL Server 5


Hi

My purpose is to have all the configuration files for my webapp (tomcat 6) in WEB-INF, including hibernate config and mapping files.

My hibernate initialization is made on a HibernateUtil class, that is called on a Servlet Filter.

I had change the code from:

Code:
...

private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
           
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
           
            throw new ExceptionInInitializerError(ex);
        }
    }

...



To:

Code:
...

private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml

String path=((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/WEB-INF");

            sessionFactory = new Configuration().configure(path + File.separator + "hibernate.cfg.xml").buildSessionFactory();
           
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
           
            throw new ExceptionInInitializerError(ex);
        }
    }

...



Well since i had this change i can't even load the application, no exception is throw, putting some breakpoints on the above code, does nothing, debug doesn't fire.

When i rollback my changes, the application works... so this is really caused by hibernate.

I'm out of ideas...

Thanks in advance.


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.