-->
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.  [ 5 posts ] 
Author Message
 Post subject: /hibernate.cfg.xml not found
PostPosted: Tue Sep 06, 2005 5:22 pm 
Beginner
Beginner

Joined: Tue Sep 06, 2005 5:16 pm
Posts: 24
Location: USA
Hi There,

My Application is unable to find the hibernate.cfg.xml file and throwing the following exception when i deployed my application in Websphere 5.1 AS.


Quote:

[9/6/05 12:43:44:913 EDT] 416e479 Configuration I net.sf.hibernate.cfg.Configuration configuring from resource: /hibernate.cfg.xml
[9/6/05 12:43:44:913 EDT] 416e479 Configuration I net.sf.hibernate.cfg.Configuration Configuration resource: /hibernate.cfg.xml
[9/6/05 12:43:44:913 EDT] 416e479 Configuration W net.sf.hibernate.cfg.Configuration /hibernate.cfg.xml not found
[9/6/05 12:43:44:929 EDT] 416e479 RequestProces W org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class java.lang.NullPointerException
[9/6/05 12:43:44:929 EDT] 416e479 WebGroup E SRVE0026E: [Servlet Error]-[]: java.lang.NullPointerException
at us.ny.state.otda.dcse.commons.persistence.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:59)
at us.ny.state.otda.dcse.login.persistence.LoginPersister.getParentRole(LoginPersister.java:64)



It works fine when i ran it locally by using test case..

Here is the code for currentSession method in my HibernateSessionFactory..

Code:

    public static Session currentSession() throws HibernateException {
        Session session = (Session) threadLocal.get();

        if (session == null) {
            if (sessionFactory == null) {
                try {
                   System.out.println("1:");
                   cfg.configure(CONFIG_FILE_LOCATION);
                   System.out.println("2:");
                    sessionFactory = cfg.buildSessionFactory();
                    System.out.println("3:");
                }
                catch (Exception e) {
                    System.err.println("%%%% Error Creating SessionFactory %%%%");
                    e.printStackTrace();
                }
            }
            session = sessionFactory.openSession();
            threadLocal.set(session);
        }

        return session;
    }



Its printing 1: and generating error in my log file..Its not printing 2:

Any Suggestion is Very Much Appreciated and thanks In Advance

JD

[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 10:13 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Is hibernate.cfg.xml @ CONFIG_FILE_LOCATION ?

Try the no-args cfg.configure() and make sure hibernate.cfg.xml is in the classpath.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 9:43 am 
Beginner
Beginner

Joined: Tue Sep 06, 2005 5:16 pm
Posts: 24
Location: USA
This is My Session Factory

Code:

public class HibernateSessionFactory {

    /**
     * Location of hibernate.cfg.xml file.
     * NOTICE: Location should be on the classpath as Hibernate uses
     * #resourceAsStream style lookup for its configuration file. That
     * is place the config file in a Java package - the default location
     * is the default Java package.<br><br>
     * Examples: <br>
     * <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
     * CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
     */
[u]    [b]private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";[/b][/u]
    /** Holds a single instance of Session */
    private static final ThreadLocal threadLocal = new ThreadLocal();

    /** The single instance of hibernate configuration */
    private static final Configuration cfg = new Configuration();

    /** The single instance of hibernate SessionFactory */
    private static net.sf.hibernate.SessionFactory sessionFactory;

    /**
     * Returns the ThreadLocal Session instance.  Lazy initialize
     * the <code>SessionFactory</code> if needed.
     *
     *  @return Session
     *  @throws HibernateException
     */
    public static Session currentSession() throws HibernateException {
        Session session = (Session) threadLocal.get();

        if (session == null) {
            if (sessionFactory == null) {
                try {

                       System.out.println("1:");
[u]  [b]                  cfg.configure(CONFIG_FILE_LOCATION);[/b]     [/u]               
                     System.out.println("2:");
                      sessionFactory = cfg.buildSessionFactory();
                }
                catch (Exception e) {
                    System.err.println("%%%% Error Creating SessionFactory %%%%");
                    e.printStackTrace();
                }
            }
            session = sessionFactory.openSession();
            threadLocal.set(session);
        }

        return session;
    }

    /**
     *  Close the single hibernate session instance.
     *
     *  @throws HibernateException
     */
    public static void closeSession() throws HibernateException {
        Session session = (Session) threadLocal.get();
        threadLocal.set(null);

       try
      {
          
        if (session != null) {
            session.close();
        }
      }              catch (Exception e) {
        System.err.println("%%%% Error Creating SessionFactory %%%%");
        e.printStackTrace();
    }
    }

    /**
     * Default constructor.
     */
    private HibernateSessionFactory() {
    }

}



In the above code ..it prints 1: after that its throwing an exception..its not printing 2:

Here is the exact problem

Quote:
[9/6/05 12:43:44:913 EDT] 416e479 Configuration I net.sf.hibernate.cfg.Configuration configuring from resource: /hibernate.cfg.xml
[9/6/05 12:43:44:913 EDT] 416e479 Configuration I net.sf.hibernate.cfg.Configuration Configuration resource: /hibernate.cfg.xml
[9/6/05 12:43:44:913 EDT] 416e479 Configuration W net.sf.hibernate.cfg.Configuration /hibernate.cfg.xml not found
[9/6/05 12:43:44:929 EDT] 416e479 RequestProces W org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class java.lang.NullPointerException
[9/6/05 12:43:44:929 EDT] 416e479 WebGroup E SRVE0026E: [Servlet Error]-[]: java.lang.NullPointerException
at us.ny.state.otda.dcse.commons.persistence.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:59)
at us.ny.state.otda.dcse.login.persistence.LoginPersister.getParentRole(LoginPersister.java:64)


Thanks

JD[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:01 am 
Newbie

Joined: Wed Sep 17, 2003 5:36 pm
Posts: 5
Just a wild guess. What JDK are you running Websphere on? I had a similar problem a while back with older JDK where it only knows how to load class files (.class) from the classpath. Other file types (e.g. .properties, .xml) were not able to be loaded from the classpath.

Ben


Top
 Profile  
 
 Post subject: save hibernate.cfg.xml inside ejbmodule folder
PostPosted: Fri Aug 11, 2006 1:38 pm 
Newbie

Joined: Sat Jul 22, 2006 1:47 pm
Posts: 11
Hi,

Save ur hibernate.cfg.xml file inside ejbmodule folder in EJB Project.


or

inside /WEB_INF/classes in web project.

Chamal.


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

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.